Pagination is a common practice to show big volume of data. It is quite important if you are showing dynamically populated data.
For myself I mostly use PEAR::Pager to display paginated data. If you are familiar with this package then you know that you can use 2 types of pagination display, as – sliding and jumping. In case of sliding display with a common practice is to use it with constructor option append:true and urlVar:<variablename>.
Let me show an example of this kind of usage –
[code lang=”php-brief”]
$Params = array(
‘itemData’ => $dataDetails,
‘perPage’ => $ViewPerPage,
‘append’ => true,
‘separator’ => ‘|’,
‘spacesBeforeSeparator’ => 1,
‘spacesAfterSeparator’ => 1,
‘clearIfVoid’ => false,
‘urlVar’ => ‘page’,
‘useSessions’ => true,
‘closeSession’ => true,
‘mode’ => ‘Sliding’,
‘importQuery’ => true,
‘linkClass’ => ‘LinkStyle’,
);
$Pager = Pager::factory($Params);
$DataDetailsInArray = $Pager->getPageData();
$PaginationLinks = $Pager->getLinks();
[/code]
Now if you print/echo the $PaginationLinks, then you will get pagination like 1 2 3 4 etc.
Now let me describe you the problem:
Say your page url is mydata.php. So mydata.php page will show the first page of paginated data. while using the pagination links you will get a page with url mydata.php?page=1. This page shows the first page of paginated data. Now you are having a page with 2 different url like mydata.php and mydata.php?page=1. In SEO this is known as duplicate content. This is not good if you are seriously deal with SEO.
Here is the correction for this. This is simple but effective.
[code lang=”php-brief”]
if(isset($_GET[‘page’]) && $_GET[‘page’] > 1)
{
$PaginationLinks[‘all’] = str_replace(array(‘?page=1″‘, ‘&page=1″‘), ‘”‘, $PaginationLinks[‘all’]);
}
[/code]
Use this code section just after generating $PaginationLinks. Hope this will help you. As always comments/suggestions are welcome. But spammers please don’t waste your time. 🙂