你好,我是Wordpress的新手,但我设计了一些元素的样式,并在其中包含了最近的文章。我的问题是,我可以让他们在5个帖子中一个接一个地重复吗?谢谢:)
<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 -->发布于 2013-05-14 18:55:58
您忘记了实现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个post。
发布于 2013-05-14 18:57:14
您可以使用:
get_archives('postbypost', 5);或
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; ?>https://stackoverflow.com/questions/16541141
复制相似问题