Answer the question
In order to leave comments, you need to log in
WP pagination code for SEO?
Good day everyone! Guys, help me to make the correct pagination for search engines - Google and Yandex, so that duplicates like page1-100 do not go into the search. There is source code in the theme, found it in function.php
/*-----------------------------------------------------------------------------------*/
/* Pagination
/*-----------------------------------------------------------------------------------*/
function pagination($pages = '', $range = 3) {
$showitems = ($range * 3)+1;
global $paged; if(empty($paged)) $paged = 1;
if($pages == '') {
global $wp_query; $pages = $wp_query->max_num_pages;
if(!$pages){ $pages = 1; }
}
if(1 != $pages) {
echo "<div class='pagination'><ul>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages)
echo "<li><a rel='nofollow' href='".get_pagenum_link(1)."'>« ".__('First','mythemeshop')."</a></li>";
if($paged > 1 && $showitems < $pages)
echo "<li><a rel='nofollow' href='".get_pagenum_link($paged - 1)."' class='inactive'>‹ ".__('Previous','mythemeshop')."</a></li>";
for ($i=1; $i <= $pages; $i++){
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )) {
echo ($paged == $i)? "<li class='current'><span class='currenttext'>".$i."</span></li>":"<li><a rel='nofollow' href='".get_pagenum_link($i)."' class='inactive'>".$i."</a></li>";
}
}
if ($paged < $pages && $showitems < $pages)
echo "<li><a rel='nofollow' href='".get_pagenum_link($paged + 1)."' class='inactive'>".__('Next','mythemeshop')." ›</a></li>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages)
echo "<a rel='nofollow' class='inactive' href='".get_pagenum_link($pages)."'>".__('Last','mythemeshop')." »</a>";
echo "</ul></div>";
}
}
Answer the question
In order to leave comments, you need to log in
Hello!
I use this pagination (found in one of the sites):
functions.php
// постраничная навигация
function wp_corenavi() {
global $wp_query;
$pages = '';
$max = $wp_query->max_num_pages;
if (!$current = get_query_var('paged')) $current = 1;
$a['base'] = str_replace(999999999, '%#%', get_pagenum_link(999999999));
$a['total'] = $max;
$a['current'] = $current;
$total = 1; //1 - выводить текст "Страница N из N", 0 - не выводить
$a['mid_size'] = 3; //сколько ссылок показывать слева и справа от текущей
$a['end_size'] = 1; //сколько ссылок показывать в начале и в конце
$a['prev_text'] = '«'; //текст ссылки "Предыдущая страница"
$a['next_text'] = '»'; //текст ссылки "Следующая страница"
if ($max > 1) echo '<div class="navigation">';
if ($total == 1 && $max > 1) $pages = '<span class="pages">Страница ' . $current . ' из ' . $max . '</span>'."\r\n";
echo $pages . paginate_links($a);
if ($max > 1) echo '</div>';
}
/* постраничная навигация */
.navigation {
text-align: center;
margin: 5px auto;
clear: both;
display: block;
width: 100%;
}
.navigation span {
display: inline-block;
background: #2C3E50;
padding: 5px 10px;
color: #fff;
}
.navigation a {
display: inline-block;
background: #2C3E50;
padding: 5px 10px;
color: #fff;
}
.navigation a:hover {
color:#fff;
text-decoration:none;
background: #00635a;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question