【问题标题】:Wordpress - display 3 recent posts from specific categoryWordpress - 显示来自特定类别的 3 个最近的帖子
【发布时间】:2013-10-17 08:08:11
【问题描述】:

我有以下代码,显示在家庭最新帖子上。如何编辑此代码以显示特定类别的最新帖子?因为我需要显示来自 3 个类别(酒店、路径和博客)的帖子。

<!-- LOOP START -->
<?php $the_query = new WP_Query( 'showposts=3' ); ?>
    <?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
    <!-- THIS DISPLAYS THE POST THUMBNAIL, The array allows the image to has a custom size but is always kept proportional -->
      <div id="hotele"><a href="<?php the_permalink() ?>"> <?php the_post_thumbnail( array(349,349) );?></a>
      <!-- THIS DISPLAYS THE POST TITLE AS A LINK TO THE MAIN POST -->
      <div><h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2></div>
      <!-- THIS DISPLAYS THE EXCERPT OF THE POST -->
      <li><?php the_excerpt(); ?></li>
      </div>
    <?php endwhile;?>
<!-- LOOP FINNISH -->

【问题讨论】:

    标签: wordpress codex


    【解决方案1】:
    $args = 'showposts=3&cat=1,2..';
    
    or
    
    $args = 'showposts=3&category_name=category_slug_1,category_slug_2...';
    
    <?php $the_query = new WP_Query($args ); ?>
    

    看看WP_Query手册。

    【讨论】:

      【解决方案2】:

      你可以使用

      wp_get_recent_posts('numberposts=5&category=8')    
      

      【讨论】:

      • 您能否进一步扩展您的答案或描述如何解决问题?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-18
      • 1970-01-01
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      相关资源
      最近更新 更多