【问题标题】:wordpress function query_posts('showposts=3&cat=1') display 4 or 5 posts instead of 3. Why?wordpress 函数 query_posts('showposts=3&cat=1') 显示 4 或 5 个帖子而不是 3 个。为什么?
【发布时间】:2019-11-08 07:22:40
【问题描述】:

我尝试使用 wordpress 函数 query_posts('showposts=3&cat=1') 显示类别 1 下的最新帖子。但它显示 4 或 5 个帖子。你能帮忙找出根本原因吗?谢谢。

<?php query_posts('showposts=3&cat=17');?>
            <div class="n-placement n-widget w-image-text" data-type="image-text" id="u-aabm">
                <div class="n-inner" id="u-aabm-i">
                    <div class="w-image-text-container">
                        <span class="w-image-text-image" style="float: left; clear: left; margin-top: 6px; margin-bottom: 6px; margin-right: 6px;">
                            <img src="<?php echo catch_that_image();?>" height="112" width="112"/>
                        </span>
                        <div class="w-image-text-text">
                            <b> 
                            <!--<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>-->
                            <?php the_title(); ?>
                       </b>
                            <div>
                                <div>
                                    <?php 
                                    if(is_category() || is_archive() || is_home() ) { 
                                        the_excerpt();
                                    } else {
                                        the_content('Read the rest of this entry &raquo;'); 
                                    } 
                                ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php endwhile; ?> 

【问题讨论】:

  • 你试过这个 query_posts('posts_per_page=3');
  • Hi Sismater,我刚才试过了,但是没用。
  • 您是否在执行查询之前重置了查询?
  • 你在哪里开while
  • 你没有循环 - codex.wordpress.org/The_Loop

标签: php wordpress


【解决方案1】:

您需要在定义 query_posts() 后开始循环。

所以代码变成:

<?php query_posts('showposts=3&cat=17');
    while (have_posts()) : the_post(); ?>
            <div class="n-placement n-widget w-image-text" data-type="image-text" id="u-aabm">
                <div class="n-inner" id="u-aabm-i">
                    <div class="w-image-text-container">
                        <span class="w-image-text-image" style="float: left; clear: left; margin-top: 6px; margin-bottom: 6px; margin-right: 6px;">
                            <img src="<?php echo catch_that_image();?>" height="112" width="112"/>
                        </span>
                        <div class="w-image-text-text">
                            <b> 
                            <!--<a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>-->
                            <?php the_title(); ?>
                       </b>
                            <div>
                                <div>
                                    <?php 
                                    if(is_category() || is_archive() || is_home() ) { 
                                        the_excerpt();
                                    } else {
                                        the_content('Read the rest of this entry &raquo;'); 
                                    } 
                                ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
 <?php endwhile; ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-08-23
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 1970-01-01
    • 2012-04-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多