Displaying Only One Post On A Sites Index In Wordpress
by Matt on , under Web Development
By default Wordpress lists your 15 most recent posts on the index page of your site. Sometimes it’s necessary to display only post, as was the case with my Gothic Fairies website. I’m sure there are probably more elegant solutions to this problem out there but regardless of this I thought I’d share my makeshift solution anyway.
I embedded the following code into the header section of the template just before the opening of the loop.
if($_SERVER["REQUEST_URI"] == "/" || $_SERVER["REQUEST_URI"] == "/index.php")
query_posts('p=3');?>
In this example, the code tests to see if the current page is the index by checking the REQUEST_URI element of the $_SERVER array. If this variable equals either “/” or “index.php” the query_posts function is called which in turn selects a certain post to be displayed with the parameter referring to the specific post ID (which in this case is 3).
With a bit of luck – the post you just referred to will be the only one which appears on the front page of your website!
November 4th, 2006 on 12:25 pm
Wordpress have an option in the admin panel to limit the posts shown on the index page.
November 4th, 2006 on 12:44 pm
Ah cool.
Is it possible to limit the number of posts for the index page alone or does that value apply for all of your categories? Say if I set it to 6 will 6 posts be shown on my index page and another 6 on say the Web Development category?