我的分页链接无法使用自定义帖子类型。
页面重新加载root / cat / page / 2 /但这对显示的帖子没有影响。刷新永久链接结构没有任何效果,所以我的猜测是问题出在查询中。
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 10;
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query(array( 'post_type' => 'press',
'orderby' => 'post_date',
'posts_per_page' => $paged,
));
while ($wp_query->have_posts()) : $wp_query->the_post();
// The following determines what the post format is and shows the correct file accordingly
$format = get_post_format();
get_template_part( '/lib/includes/post-formats/'.$format );
if($format == '')
get_template_part( '/lib/includes/post-formats/standard' );
endwhile;
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
) );
$wp_query = null; $wp_query = $temp; ?>
答案 0 :(得分:0)
posts_per_page
和showposts
基本相同。这些参数定义页面上显示的帖子数量。不推荐使用showposts
,而应使用posts_per_page
。分页的相关参数是paged
。
因此查询参数应如下所示:
array(
'post_type' => 'press',
'orderby' => 'post_date',
'posts_per_page' => 10,
'paged' => $paged
)
供参考,请参阅WP_Query, pagination parameters上的代码。
答案 1 :(得分:0)
答案结果是
'orderby' => 'date',
而不是
'orderby' => 'post_date',