Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WordPress have_posts()限制检索到的帖子数量_Wordpress - Fatal编程技术网

WordPress have_posts()限制检索到的帖子数量

WordPress have_posts()限制检索到的帖子数量,wordpress,Wordpress,我有以下代码(继承的,不是我写的),我很难理解为什么它只带回最近的4篇文章,而不是全部。也就是说,我不想一下子就把所有的都搞定,但我希望能够控制有多少人回来 此外,我还需要编写一个函数,该函数底部有一个链接,上面写着“加载更多”,单击该链接后,将(通过AJAX)返回接下来的四篇(或任意多篇)文章,以便在已经显示的文章下方立即渲染。我该怎么做呢 谢谢 <?php if (have_posts()): ?> <div class="postSecti

我有以下代码(继承的,不是我写的),我很难理解为什么它只带回最近的4篇文章,而不是全部。也就是说,我不想一下子就把所有的都搞定,但我希望能够控制有多少人回来

此外,我还需要编写一个函数,该函数底部有一个链接,上面写着“加载更多”,单击该链接后,将(通过AJAX)返回接下来的四篇(或任意多篇)文章,以便在已经显示的文章下方立即渲染。我该怎么做呢

谢谢

        <?php if (have_posts()): ?>
        <div class="postSection">
            <?php
            while (have_posts()) : the_post();
                $pdf_download = get_post_meta($post->ID, 'pdf_download', true);
                $pdf_label = get_post_meta($post->ID, 'pdf_label', true);
                ?>
                <div class='postBox <?php foreach ((get_the_category()) as $cats) {
                    echo $cats->slug . ' ';
                } ?>'>
                    <div class="postImage">
                        <a href="<?php the_permalink(); ?>"
                           title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(); ?></a>
                    </div>
                    <div class="postContent">
                        <h3><a href="<?php the_permalink(); ?>"
                               title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
                        </h3>

                        <div class="postExcerpt">
                            <p><?php the_excerpt_rss(); ?>&nbsp;&nbsp;&nbsp;<a class="readMore"
                                                                               href="<?php the_permalink(); ?>"
                                                                               title="<?php the_title_attribute(); ?>">Read
                                    More</a></p>
                        </div>
                    </div>
                </div>
            <?php endwhile; ?>
        </div>
    <?php endif;


一般来说,这是一个阅读偏好设置。啊!谢谢我去看看!也就是说,我可以根据我所在的页面更改号码吗?例如,我只想在主页上显示前四个,但我想在不同类别的登录页上显示6个。我想出来了。您可以将
(如果不是10,则可以任意添加)添加到您想要带回非标准金额的代码之前。永远不要使用
查询帖子
,它会破坏主查询对象,许多插件和自定义代码取决于主查询对象。