【发布时间】:2014-01-21 18:30:56
【问题描述】:
我正在使用简码显示帖子,它只显示 5 个帖子,我正在使用 wp_pagenavi 插件进行分页,但没有显示分页。以下是我的代码,请帮忙。
global $post;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array( 'post_type' => 'post', 'cat' => '2', 'paged' => $paged );
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
ob_start();
?>
<div class="clearfix"></div>
<div class="issue-articles-wrap all-articles-wrap">
<?php
while ( $loop->have_posts() ) : $loop->the_post();
$loop->the_post();
$thumb_url = '';
$full_width = 'full-width-article';
if( has_post_thumbnail() ){
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail' );
$thumb_url = $thumb['0'];
$full_width = '';
}
if( $post->ID > 0 ){
?>
<div class="issue-item issue-item-<?php echo $post->ID; ?>">
<?php if( $thumb_url != '' ){ ?>
<div class="thumb-article">
<a href="<?php the_permalink(); ?>"><img src="<?php echo $thumb_url; ?>" alt="<?php the_title(); ?>"></a>
</div><!--thumb-article-->
<?php } ?>
<div class="summary-article <?php echo $full_width; ?>">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php the_excerpt(); ?>
</div><!--summary-article-->
<div class="clearfix"></div>
</div><!--issue-item-->
<?php
} // end of if( $post->ID > 0 )
endwhile;
wp_pagenavi();
wp_reset_query();
?>
</div><!--issue-articles-wrap all-articles-wrap-->
<?php
$rep = ob_get_contents();
ob_end_clean();
} // end of if ( $loop->have_posts() )
return $rep;
我也试过自定义分页,但失败了,如果我通过posts_per_page = -1,它会显示所有帖子。
请帮我运行分页,非常感谢您。
【问题讨论】:
标签: wordpress wordpress-theming