我对分页有疑问,在单击数字下一个按钮时,下一页显示与上一页相同的帖子。
帖子查询基本上使用自定义类别下拉列表,并从特定的帖子标签获取。
分页能够从类别和标签获取帖子,但无法动态更改帖子。
请帮助。
<?php
wp_dropdown_categories( 'show_count=0&hierarchical=1&exclude=1,203,202,199,198,197,196&hide_empty=1&value_field=analgesic-anti-inflammatory&show_option_none=Select Category' ); ?>
<script type="text/javascript">
var dropdown = document.getElementById("cat");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
location.href = "?cat="+dropdown.options[dropdown.selectedIndex].value;
}
}
dropdown.onchange = onCatChange;
</script>
<?php
wp_reset_query();
$post_tag = 'futura';
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'post', 'posts_per_page' => 8,'tag'=> $post_tag, 'taxonomy' => 'category', 'category__in' => $_GET['cat'], 'max_num_pages' => '50', 'offset' =>20, 'paged'=>$paged);
query_posts($args);
$custom_query = new WP_Query( $args );
// The Loop
while ( $custom_query->have_posts() ) : $custom_query->the_post();
?>
<div class="prod_item">
<a href="<?php the_permalink(); ?>">
<span class="title"><?php the_title();
?></span>
<?php the_post_thumbnail( 'prod_thumb' ); ?>
<span class="know_more">KNOW MORE<i class="fa fa-angle-right"></i></span>
</a>
</div>
<?php
endwhile;
if (function_exists("pagination")) {
pagination($custom_query->max_num_pages);
}
wp_reset_query();
function.php
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 "<div class=\"pagination\"><span>Page ".$paged." of ".$pages."</span>";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".get_pagenum_link(1)."'>« First</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>‹ Previous</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)."\">Next ›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".get_pagenum_link($pages)."'>Last »</a>";
echo "</div>\n";
}
}