类别WP中的帖子列表中的导航



谁能帮我改进类别.php中的代码,我需要在 3 个帖子下添加一个简单的导航(旧条目)。当我使用<?php posts_nav_link(); ?>时,什么都没有出现。这是我的代码

    <div id="category">
<?php
$args = array( 'posts_per_page' => 3, 'offset'=> 0, 'category' => 6 );
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
    <div class="news">
        <a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a> <?php the_content(); ?>
    </div>
<?php endforeach; 
wp_reset_postdata();?>
</div></div>

我不确定查询中的类别参数,但请尝试使用替换查询部分w

$args = array('posts_per_page' => 3 , 'cat' => 3)

<?php
$args = array('posts_per_page' => 3 , 'cat' => 3);
// The Query
$the_query = new WP_Query( $args );
// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
?>
<div class="news">
        <a href="<?php the_permalink(); ?>"><h2><?php the_title(); ?></h2></a> <?php the_content(); ?>
    </div>
<?php }
      } else {
    // no posts found
}

如果不起作用,您可以尝试通过<?php get_the_permalink(); ?>使用

最新更新