簡體   English   中英

wordpress從一個類別獲取帖子

[英]wordpress get posts from a category

嗨,我正在嘗試建立我的第一個wordpress網站。 我一直試圖從兩個不同的類別中帶出蝙蝠帖子,並將它們顯示在同一頁面上。 我將其帶回去,但它始終將它們隨機排列。 我想要一個來自一個類別的帖子,下面是一個來自另一類別的帖子。

到目前為止我所得到的

<?php get_head(); ?>

<div id="container">
<?php get_header(); ?>
<?php get_banner(); ?>

    <div class=" center content" role="main">
      <div id="posts">


          <div class="news">
                <?php query_posts('catname=news&showposts=3'); while (have_posts()) : the_post(); the_title(); the_content(); 
                endwhile;?>

                <div class="clear"></div>
          </div>
             <div class="msghead">
            <?php query_posts('catname=msghead&showposts=1'); while (have_posts()) : the_post(); the_title(); the_content(); 
            endwhile;?>

           </div>
        </div>
    </div>

    <div class="sidebardiv">
       <?php get_sidebar(); ?>
    <div class="clear">
    </div>
</div>
</div>
<?php get_footer(); ?>

</div>

您是否嘗試過order和orderby查詢參數?

http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

您的代碼可能像這樣,按日期順序降序排列:

<?php query_posts('cat=news&showposts=3&orderby=date'); while (have_posts()) : the_post(); the_title(); the_content(); 
endwhile;?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM