任何人都可以帮我编辑此代码吗? 我有两个类别,点击后我会显示此类别的所有帖子。 现在我在两个类别中都看到了类别ID 8的内容。 我的代码来自category.php
<?php
$args = array( 'posts_per_page' => 5, 'category' => 8);
$myposts = get_posts( $args );
foreach ( $myposts as $post ) : setup_postdata( $post ); ?>
<li class="ikonakategoriiwpisu">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?><?php the_post_thumbnail( 'thumbnail' ); ?> </a><?php the_excerpt(); ?>
</li>
<?php endforeach;
wp_reset_postdata();?>
答案 0 :(得分:1)
如果您的网页网址有类别,那么您可以像这样使用
$category_id = get_query_var('cat');
$args = array( 'posts_per_page' => 5, 'category' =>$category_id );