【问题标题】:Show 4 latest posts from a specific tag in Wordpress在 Wordpress 中显示来自特定标签的 4 个最新帖子
【发布时间】:2018-03-16 07:08:58
【问题描述】:

我想在 WordPress 中显示来自标签“视频”的 4 个最新帖子,我该怎么做?

我试过这个循环,但我只想要 4 个最新帖子。

<?php query_posts('tag=video'); ?>
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
        <?php the_title(); ?>
        <?php endwhile; ?>
    <?php else : ?>
        no video
   <?php endif; ?>

【问题讨论】:

  • 请看我的回答,它会解决你的问题。如果您仍然遇到此问题,请告诉我。

标签: php wordpress loops tags wordpress-theming


【解决方案1】:

试试下面的代码:

   <?php

            $query = new WP_Query( array(
                'posts_per_page' => 4,
                'no_found_rows'  => true,
                'tag'            => 'video'
            ) );

            if ( $query->have_posts() ) :

                while ( $query->have_posts() ) : $query->the_post();

                    // the_title();

                endwhile; 

                wp_reset_postdata();

            endif; 
     ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多