Jump to content
ceberlin

Paginator and SEO

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

Share this post


Link to post
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. 

Share this post


Link to post
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

Share this post


Link to post
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(); ?>

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...