我想在class.php中使用分页进行make循环。我的循环看起来像这样:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query( array(
'post_type' => 'blog',
'posts_per_page' => 2,
'orderby'=> 'menu_order',
'paged' => $paged
) );
while ($wp_query->have_posts()) : $wp_query->the_post();
$url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<!-- start article -->
<!-- end article -->
<?php endwhile; ?>
<?php get_template_part('pagination') ?>
和功能:
function pagination()
{
global $wp_query;
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'prev_text' => __('<i class="fa fa-chevron-left"></i>'),
'next_text' => __('<i class="fa fa-chevron-right"></i>'),
'total' => $wp_query->max_num_pages,
));
}
当我点击分页链接时,他将我发送到site/?cat=9&paged=2
,这个网站是索引,而不是我的下一页帖子。我尝试了很多方法而且我不知道出了什么问题......
有什么建议吗?
PS。不要想知道为什么我有分页作为template_part:)
答案 0 :(得分:0)
这是完全相同的工作。我检查一下。
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$wp_query = new WP_Query(array('post_type' => 'blog','posts_per_page' => 2,'orderby'=> 'menu_order','paged'=>$paged));
while ( $wp_query->have_posts() ) : $wp_query->the_post();the_title();endwhile;
对于分页,我在同一页面上使用您的代码。
$big = 999999999;
echo paginate_links(array(
'base' => str_replace($big, '%#%', get_pagenum_link($big)),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'prev_text' => __(''),
'next_text' => __(''),
'total' => $wp_query->max_num_pages,
));