Stacknerd
Stacknerd

Reputation: 469

Wordpress, changing the value of "Blog pages show at most" with PHP

Ok so i normally display 8 post per pages, but with the selection of a parameter, i want the user to see only a single post per page differently. That is not a problem on how i will show it differently as its already done, but my issue is when i try to change the loop.

I've looked for hours online and i beleive i just don't know enough of Wordpress, but i can tell that

query_posts('showposts=1');

doesnt fix the issue.

Basically i need to only show a single post, so i would like to know if there is a simple way to change the value of this famous "Blog pages show at most" in the settings sections. I just want to change that value before i go into my loop. Thats it thats all, if somone has an awnser to this, i would be really happy to finally fix this problem.

Thanks.

Upvotes: 1

Views: 2968

Answers (3)

Dominic P
Dominic P

Reputation: 2404

You could take a look at the pre_get_posts hook. It is generally preferred over the query_posts() function because it doesn't cause a second query to run.

Also, if you want to learn more about WP_Query and how WordPress uses it, I highly recommend this video: You Don't Know Query

Upvotes: 0

Stacknerd
Stacknerd

Reputation: 469

update_option( 'posts_per_page', 1 );

This code snippet is changing the actual value of the Blog pages show at most. It did work and you can see it when you go into the admin tool. Although be carefull its permanant, so use this with high attention.

Upvotes: 3

Mark Bonnici
Mark Bonnici

Reputation: 21

I think you should be using the following snippet:

query_posts( 'posts_per_page=1' );

this is depicted in query_posts wordpress codex page

Upvotes: 1

Related Questions