我的主导航菜单下有4个div,我不会在每个div中显示单个类别的最近帖子。我使用此代码,但在每个div中我都有相同的内容(我更改了类别ID)。
<?php // display a list of recent case studies
// instantiate an instance of WP_Query as a variable $recentPosts
$recentPosts = new WP_Query();
// get last 10 posts from category 7 (case studies)
$recentPosts->query('showposts=4&cat=4');
// utilize two methods to get at template tags (below)
while ($recentPosts->have_posts()) :
$recentPosts->the_post();
?>
<div class="slide" ><a href="<?php // bump out what we need courtesy of template tags
the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><h2><?php the_title(); ?></h2><?php echo excerpt(20); ?></a></div>
<?php endwhile; ?>
答案 0 :(得分:0)
试试这段代码:
<?php
$args = array( 'numberposts' => 6, 'order'=> 'DESC', 'orderby' => 'post_date', 'category' => 3 );
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post);
?>
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endforeach; ?>