我想做的是显示“新闻”类别中的每一篇文章(在我的例子中,“新闻”类别的ID是13),每页5篇文章。页面上会显示分页链接,但当我单击“上一页”链接时,它只会显示类别中的前5篇文章。
页面新闻的内容。php:
<?php get_header(); ?>
<h1 class="title">Latest News</h1>
<?php
/*$args = array(\'cat\' => 13);
$posts = new WP_Query($args);*/
global $paged;
global $wp_query;
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query(array(\'cat=13\', \'paged=\'.$paged));
if ($wp_query->have_posts()) :
?>
<ul id="news">
<?php
while ($wp_query->have_posts()) : $wp_query->the_post();
?>
<li>
<article>
<h2 class="post-title"><a href="<?php esc_url( the_permalink() ); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<time datetime="<?php the_time( \'Y-m-d\' ); ?>" pubdate><?php the_date(); ?> <?php the_time(); ?></time>
<?php the_content(); ?>
</article>
</li>
<?php
endwhile;
?>
</ul>
<div class="news-nav">
<?php next_posts_link( __( \'← Older posts\')); ?>
<?php previous_posts_link( __( \'Newer posts →\')); ?>
</div>
<?php
$wp_query = null;
$wp_query = $temp;
else :
?>
<h2>It looks like there\'s nothing happening at the moment.</h2>
<?php endif; ?>
<?php get_footer(); ?>