显示3个来自特色类别的最新帖子(Wordpress)

时间:2013-03-28 12:06:09

标签: php wordpress loops posts

在我刚刚开始的工作中,我想只显示3个最新帖子,其中包含标签。对于" The Loop"一定是一个非常基本的事情,但我无法在任何地方找到答案,感觉我到处都是:(

有人可以帮助我吗?

3 个答案:

答案 0 :(得分:3)

您应该查看WP参考https://codex.wordpress.org/Class_Reference/WP_Query 它会是这样的:

$featured_posts = new WP_Query(array(
    'tag' => 'featured',
    'posts_per_page' => 3,
));

答案 1 :(得分:1)

query_posts('tag=featured&posts_per_page=3&order=DESC'); // show latest 3 posts on featured tag

//query_posts('category_name=featured&tag=featured&posts_per_page=3&order=DESC'); // show latest 3 posts on featured tag and featured categorey

<?php if (have_posts()) : ?>
        <?php while (have_posts()) : the_post(); ?>    
        <!-- do stuff ... -->
        <?php endwhile; ?>
<?php endif; ?>

答案 2 :(得分:-1)

使用以下查询获取最新的3个帖子。

"SELECT * FROM tablename WHERE featured=1 ORDER BY id DESC LIMIT 3"

* ID = PK