0

在我正在处理的起始页上,我只想显示 3 个最新帖子,女巫具有该标签。必须是与“The Loop”有关的非常基本的事情,但我在任何地方都找不到答案,感觉就像我真的到处都看过:(

有人能帮我吗?

4

3 回答 3

3

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

$featured_posts = new WP_Query(array(
    'tag' => 'featured',
    'posts_per_page' => 3,
));
于 2013-03-28T12:15:22.330 回答
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; ?>
于 2013-03-28T12:13:45.000 回答
-1

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

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

*id=pk

于 2013-03-28T12:11:31.967 回答