2013-05-14 53 views
0

你好Im新的WordPress的,但我設計了一些元素,並在他們最近的帖子。我的問題是,我可以讓他們重複5次嗎?謝謝:)WordPress的query_posts()

<div id="main_content"> 
    <h2>Latest Products</h2> 

    <div class="latest_products"> 
     <div class="group"> 
      <?php query_posts("post_per_page=1"); the_post(); ?> 
      <h3 class="stick_note"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
      <div class="pro_content"> 
       <div class="product_thumbnail"> <?php the_post_thumbnail('thumbnail'); ?> </div> 
       <p><?php the_excerpt(); ?></p> 
      </div> 
     </div> 
    </div> <!-- END LATEST PRODUCTS --> 


</div> <!-- END Main Content --> 
+1

更具體。你的問題對於不知道你建立什麼的人以及爲什麼沒有任何意義。 – 2013-05-14 10:47:12

+0

我在博客中有帖子,在主頁我想展示最近的5篇帖子,這段代碼給我帶來了第一個。我想這整個結構重複每個帖子得到5個 – 2013-05-14 10:52:29

回答

0

你忘了執行The Loop(點擊查看詳細信息)。

一個完整的WordPress的循環如下:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
    ...render your post here, it will keep repeating... 
<?php endwhile; else: ?> 
<p>Sorry, no posts matched your criteria.</p> 
<?php endif; ?> 

既然你不是有一個實際的循環來實現做只能使1篇文章。

+0

我試過了,它只重複最近的帖子永遠,我需要最新的5個職位被顯示,這可能嗎? – 2013-05-14 11:00:26

+0

是的,你是對的。 – 2013-05-14 11:00:38

+0

@ user2381305你也應該改變'query_posts(「post_per_page = 1」)''query_posts(「post_per_page = 5」)'我想...... – 2013-05-14 11:02:59

0

您可以使用:

get_archives('postbypost', 5); 

OR

query_posts("showposts=5"); 

這可以幫助您?在你的問題中更具體。

您可以在WordPress的文件答案: http://codex.wordpress.org/Template_Tags/get_posts http://codex.wordpress.org/Template_Tags/query_posts http://codex.wordpress.org/Template_Tags/wp_get_archives

編輯:

$args = array('numberposts' => 5, 'order'=> 'ASC'); 
$postslist = get_posts($args); 

EDIT2:

你可以這樣做:

$args = array('numberposts' => 5, 'order'=> 'ASC'); 
$postslist = get_posts($args); 
foreach($postslist as $post) : setup_postdata($post); ?> 
    <li> 
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 
    </li> 
<?php endforeach; ?>