Jump to content

Paginator and SEO


ceberlin
 Share

Recommended Posts

Google wants special code in the header to identify pages with a paginator correctly:

<link rel="prev" href="http://www.example.com/article?page=1" />
<link rel="next" href="http://www.example.com/article?page=3" />

Is there a way to do that with the paginator module already - or with some small tweaks? 

All the needed information should be there already (like "is there a next/prev page" and "what are the links")

and there might be just some additional rendering for the header part of the webpage necessary.

Source/read more: http://googlewebmastercentral.blogspot.de/2011/09/pagination-with-relnext-and-relprev.html

Link to comment
Share on other sites

Couldn't you just use the current page number and generate the URLs according to this?

 $input->pageNum gives you the current page.  Example:

$nextURL = $config->httpHost . "page-" . $input->pageNum + 1;

Of course, you would need to deal with the last and first page. 

Link to comment
Share on other sites

Philipp is right -- this is roughly the logic I used a while ago:

if ($input->pageNum) {
    $limit = 15; // whatever limit you're actually using
    if ($input->pageNum > 1) {
        echo "<link rel='prev' href='{$page->url}{$config->pageNumUrlPrefix}".($input->pageNum-1)."' />";
    }
    if ($input->pageNum * $limit < $items->getTotal()) {
        echo "<link rel='next' href='{$page->url}{$config->pageNumUrlPrefix}".($input->pageNum+1)."' />";
    }
}
  • Like 3
Link to comment
Share on other sites

I see... I need to calculate the loop earlier (in the head already) and then have the info I need ...

Here is my code in case s.o. wants to play with it further:

I am trying this now within the page's head:

$limit = 12; // the "limit"-setting used on this page
$children = $page->children("limit=" . $limit);
$totalpages = ceil($children->getTotal() / $limit);

// PAGINATOR: set SEO tags for Google
if ($input->pageNum) {
    if ($input->pageNum < $totalpages) {
        echo "<link rel='next' href='" . $page->url . $config->pageNumUrlPrefix . ($input->pageNum + 1) . "' />";
    }
    if ($input->pageNum > 1) {
        echo "<link rel='prev' href='" . $page->url . $config->pageNumUrlPrefix . ($input->pageNum - 1) . "' />";
    }
}

Within the body comes the loop and the paginator:

<?php foreach($children as $child): ?>

...

<?php endforeach; ?>

<?=$children->renderPager(); ?>
Link to comment
Share on other sites

This would give you a pager without enabling PageNumbers on template, thus using /?page=2 instead of /page2

$pageNum = $input->get->page ? $input->get->page - 1 : 0;
$limit = 5;
$start = $pageNum * $limit;
$result = $page->children("start=$start, limit=$limit");

echo $result->renderPager();
foreach($result as $p) echo "<p>$p->url</p>";
echo $result->renderPager();
  • Like 4
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...