0

您好,我是 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 -->
4

2 回答 2

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 个帖子。

于 2013-05-14T10:55:58.157 回答
0

您可以使用:

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 );

编辑2:

你可以做:

$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; ?>
于 2013-05-14T10:57:13.630 回答