Có nhiều plugins hỗ trợ công tác chuyển trang cho wordpress, ngay cả bản thân wordpress cũng đã hỗ trợ phần chuyển trang. Nhưng để cho bắt mắt và tiện dụng trong công tác tìm kiếm duyệt website, thu hút lượng page views cho site. Mình trích lượt đoạn code trong một theme mà mình có share cho các bạn.
1. Đầu tiên các bạn mở file funtions.php thêm vào code:
/********************************************************************
Page Navi
********************************************************************/
function depvn_pagination($pages = '', $range = 9){
$showitems = ($range * 2)+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'><span class='textpage'>TRANG</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>«</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='.get_pagenum_link($paged – 1).'>‹</a>";
for ($i=1; $i <= $pages; $i++){
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>»</a>";
echo "</div>\n";
}
}
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
Các bạn thêm vào sau thẻ <?php nhe.
2. Mở style.css thêm vào code:
.pagination {
clear: both;
padding: 10px 20px 10px 20px;
position: relative;
font-size: 11px;
line-height: 13px;
}
.pagination {
clear: both;
padding: 10px 20px 10px 20px;
position: relative;
font-size: 11px;
line-height: 13px;
}
.pagination span, .pagination a {
display: block;
float: left;
margin: 2px 2px 2px 0;
padding: 6px 9px 5px 9px;
text-decoration: none;
width: auto;
color: #000;
background: #FF6600;
}
.pagination a:hover{
color: #D20045;
background: #000;
}
.pagination span.textpage {
background: #FF6600;
color: #000;
}
.pagination .current{
padding: 6px 9px 5px 9px;
background: #000;
color: #D20045;
}
3. Chèn vào vị trí mà các bạn muốn:
<div class="pagination">
<?php depvn_pagination($additional_loop&max_num_pages); ?></div>
4. Kết quả:
1. Đầu tiên các bạn mở file funtions.php thêm vào code:
/********************************************************************
Page Navi
********************************************************************/
function depvn_pagination($pages = '', $range = 9){
$showitems = ($range * 2)+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'><span class='textpage'>TRANG</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>«</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='.get_pagenum_link($paged – 1).'>‹</a>";
for ($i=1; $i <= $pages; $i++){
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems )){
echo ($paged == $i)? "<span class='current'>".$i."</span>":"<a href='".get_pagenum_link($i)."' class='inactive' >".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($paged + 1)."'>›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>»</a>";
echo "</div>\n";
}
}
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>',
));
Các bạn thêm vào sau thẻ <?php nhe.
2. Mở style.css thêm vào code:
.pagination {
clear: both;
padding: 10px 20px 10px 20px;
position: relative;
font-size: 11px;
line-height: 13px;
}
.pagination {
clear: both;
padding: 10px 20px 10px 20px;
position: relative;
font-size: 11px;
line-height: 13px;
}
.pagination span, .pagination a {
display: block;
float: left;
margin: 2px 2px 2px 0;
padding: 6px 9px 5px 9px;
text-decoration: none;
width: auto;
color: #000;
background: #FF6600;
}
.pagination a:hover{
color: #D20045;
background: #000;
}
.pagination span.textpage {
background: #FF6600;
color: #000;
}
.pagination .current{
padding: 6px 9px 5px 9px;
background: #000;
color: #D20045;
}
3. Chèn vào vị trí mà các bạn muốn:
<div class="pagination">
<?php depvn_pagination($additional_loop&max_num_pages); ?></div>
4. Kết quả:




0 nhận xét:
Đăng nhận xét