Skip to content
Browse files

SEO pagination URL

  • Loading branch information...
1 parent 9cb4e7e commit c96a43ffad57f49eb3400a1d2e7c297da3257602 @DanielMuller committed Feb 12, 2013
Showing with 42 additions and 13 deletions.
  1. +42 −13 views/paginator.html.php
View
55 views/paginator.html.php
@@ -44,6 +44,35 @@
?>
<?
+ # SEO pagination (http://www.milesjcarter.co.uk/blog/photos-on-the-web/gallery-3-seo-part-perfect-url-scheme/)
+ function seo_pagination($url) {
+ $pattern = '/\?page=([0-9]+)/';
+ $replacement = '/page/$1';
+ #REMOVE REDUNDANT /PAGE/1"
+ $pattern2 = '/\/page\/1$/';
+ $replacement2 = '';
+ $url=preg_replace($pattern, $replacement, $url);
+ $url=preg_replace($pattern2, $replacement2, $url);
+ return $url;
+ }
+
+ #PREVIOUS PAGE#
+ if (isset($previous_page_url)){
+ $previous_page_url = seo_pagination($previous_page_url);
+ }
+ #NEXT PAGE#
+ if (isset($next_page_url)) {
+ $next_page_url = seo_pagination($next_page_url);
+ }
+ #FIRST PAGE#
+ if (isset($first_page_url)) {
+ $first_page_url = seo_pagination($first_page_url);
+ }
+ #LAST PAGE#
+ if (isset($last_page_url)){
+ $last_page_url = seo_pagination($last_page_url);
+ }
+
$_pagelist = array();
switch ($page_type) {
@@ -55,7 +84,7 @@
$total_pages = $max_pages;
// Prepare page url list
for ($i = 1; $i <= $total_pages; $i++):
- $_pagelist[$i] = url::site(url::merge(array("page" => $i)));
+ $_pagelist[$i] = seo_pagination(url::site(url::merge(array("page" => $i))));
endfor;
break;
case "item":
@@ -64,7 +93,7 @@
endif;
if (isset($position)):
- $current_page = $position;
+ $current_page = $position;
else:
$current_page = 1;
endif;
@@ -73,14 +102,14 @@
if (isset($parent)):
$siblings = $parent->children();
for ($i = 1; $i <= $total; $i++):
- $_pagelist[$i] = $siblings[$i-1]->url();
+ $_pagelist[$i] = seo_pagination($siblings[$i-1]->url());
endfor;
endif;
break;
default:
$current_page = 1;
$total_pages = 1;
- $_pagelist[1] = url::site();
+ $_pagelist[1] = seo_pagination(url::site());
break;
}
@@ -92,25 +121,25 @@
for ($i = 1; $i <= $total_pages; $i++):
if ($i == $current_page):
$pagination_msg .= '<span>' . t($i) . '</span>';
- else:
+ else:
$pagination_msg .= '<span><a href="' . $_pagelist[$i] . '" title="' . t("Page") . ' ' . t($i) . '">' . t($i) . '</a></span>';
endif;
if ($i < $total_pages):
- $pagination_msg .= '&middot;';
+ $pagination_msg .= '&middot;';
endif;
endfor;
elseif ($current_page < 9):
for ($i = 1; $i <= 10; $i++):
- if ($i == $current_page):
+ if ($i == $current_page):
$pagination_msg .= '<span>' . t($i) . '</span>';
else:
$pagination_msg .= '<span><a href="' . $_pagelist[$i] . '" title="' . t("Page") . ' ' . t($i) . '">' . t($i) . '</a></span>';
endif;
if ($i < 10):
- $pagination_msg .= '&middot;';
+ $pagination_msg .= '&middot;';
endif;
endfor;
-
+
$pagination_msg .= '&hellip;';
$pagination_msg .= '<span><a href="' . $_pagelist[$total_pages - 1] . '" title="' . t("Page") . ' ' . t($total_pages - 1) . '">' . t($total_pages - 1) . '</a></span>';
$pagination_msg .= '&middot;';
@@ -123,7 +152,7 @@
$pagination_msg .= '&hellip;';
for ($i = $total_pages - 9; $i <= $total_pages; $i++):
- if ($i == $current_page):
+ if ($i == $current_page):
$pagination_msg .= '<span>' . t($i) . '</span>';
else:
$pagination_msg .= '<span><a href="' . $_pagelist[$i] . '" title="' . t("Page") . ' ' . t($i) . '">' . t($i) . '</a></span>';
@@ -140,7 +169,7 @@
$pagination_msg .= '&hellip;';
for ($i = $current_page - 5; $i <= $current_page + 5; $i++):
- if ($i == $current_page):
+ if ($i == $current_page):
$pagination_msg .= '<span>' . t($i) . '</span>';
else:
$pagination_msg .= '<span><a href="' . $_pagelist[$i] . '" title="' . t("Page") . ' ' . t($i) . '">' . t($i) . '</a></span>';
@@ -155,11 +184,11 @@
$pagination_msg .= '&middot;';
$pagination_msg .= '<span><a href="' . $_pagelist[$total_pages] . '" title="' . t("Page") . ' ' . t($total_pages) . '">' . t($total_pages) . '</a></span>';
endif;
- endif;
+ endif;
?>
<ul class="g-paginator">
- <li class="g-pagination"><?= $pagination_msg ?></li>
+ <li class="g-pagination"><?= $pagination_msg ?></li>
<li class="g-navigation">
<? if ($current_page > 1): ?>
<a title="<?= t("first") ?>" id="g-navi-first" href="<?= $_pagelist[1] ?>"><span class="ui-icon ui-icon-first">&nbsp;</span></a>

0 comments on commit c96a43f

Please sign in to comment.
Something went wrong with that request. Please try again.