简体   繁体   English

WordPress:特定页面上的无限帖子

[英]Wordpress: Unlimitet Posts on specific Page

for general, the limit of posts per page in my wordpress blog is set to 3 Post. 通常,我的wordpress博客中每页的帖子数限制为3个。

But on one specific Page i need to show unlimited Posts. 但是在一个特定的页面上,我需要显示无限的帖子。 Anyone knows how to do this.. i don't get it. 任何人都知道该怎么做..我不明白。

The code on this specific Page (projects) right now 现在,此特定页面(项目)上的代码

<div id="content" class="fullProjects clearfix full grid">                                  
                <?php while (have_posts()) : the_post(); ?>                                         
                    <?php the_content(); ?>                                                     
                <?php endwhile; ?>  

The 3 Post limit is set in the wordpress admin - backend - not by code. 3个帖子的限制是在wordpress admin-后端-不是通过代码中设置的。

Thank you for your help! 谢谢您的帮助!

You can over-ride the settings from the admin page programmatically. 您可以通过编程方式覆盖管理页面中的设置。 You're going to need to tweak your query, though, and over-ride the loop. 不过,您将需要调整查询并覆盖循环。 I think something like this will work: 我认为类似这样的方法会起作用:

global $wp_query;

$args = array_merge( $wp_query->query_vars, array( 'posts_per_page' => '-1' ) );
query_posts( $args );

while ( have_posts() ) : the_post();
    the_content();
endwhile;

(I'm putting this together from a couple of different man pages, so it might not be perfect; but it should point you in the right direction) (我将这些内容从几个不同的手册页中放在一起,所以它可能并不完美;但是应该为您指明正确的方向)

Effectively, you're making a new query for posts (the query_posts call). 实际上,您正在对帖子进行新查询( query_posts调用)。 You're passing it a new set of parameters, created from the existing ones via the array_merge ; 您将通过array_merge从现有参数中传递给它一组新的参数; and you're explicitly setting posts_per_page to -1, which should turn off the limit for the number of posts. 并且您明确将posts_per_page设置为-1,这应该会关闭帖子数量的限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM