STEP 1. Add the following function to your functions.php file:
function pagination($pages = '', $range = 2)
{
$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 "\n";
}
}
STEP 2. To style it, add the following to your stylesheet (typically style.css).
.pagination {
clear:both;
padding:20px 0;
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:#fff;
background: #555;
}
.pagination a:hover{
color:#fff;
background: #3279BB;
}
.pagination .current{
padding:6px 9px 5px 9px;
background: #3279BB;
color:#fff;
}
STEP 3: Final step, Put in your template file:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$arg= array('post_type' => 'post-type',
'taxonomy' => 'texonomy-slug',
'term'=> 'term-slug',
'paged' => $paged,
'posts_per_page' => 5,
'orderby' => 'date',
'post_status'=>'publish'
);
$loop = new WP_Query($arg);
?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php endwhile; ?>
<?php if (function_exists("pagination")) {
pagination($loop->max_num_pages);
}
No comments:
Post a Comment