2013-05-14 37 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; ?>