TV Show Tees - T-shirts and gifts of all your favorite television programs
Home » Web Things » Change number of posts displayed on Wordpress homepage

Change number of posts displayed on Wordpress homepage


by Arthur
Posted on Sunday, July 9th, 2006 at 8:16 pm CET

Wordpress has a setting on the Reading Options page where you can specify the number of posts per page. By default this is set to “10″, and this number declares that there will be ten posts per page on the homepage, in the search results, and on every archive / category page.

In other words, if you only want to display one post on your Wordpress blog’s homepage, then changing this setting to “1″ is not an option, as that would also only show one search result per page and one post per archive page.

The simplest way to fix this is to add a bit of extra code to your theme’s index.php.

The Wordpress loop on your homepage starts like this:


< ?php
while (have_posts()) : the_post();
?>

To display only the latest single post on your homepage, change this code to the following:


< ?php
$displayposts=1;
$postcount=0;
while (have_posts() && $postcount< $displayposts) : the_post();
$postcount=$postcount+1;
?>

Here we are adding a expression to the while loop, namely that $postcount should be smaller than $displayposts.

Change the variable $displayposts to any number smaller than the posts per page number you set on the reading options page. This will determine the number of posts displayed on the page.

blinkbits BlinkList blogmarks co.mments connotea del.icio.us De.lirio.us digg Fark feedmelinks Furl LinkaGoGo Ma.gnolia
NewsVine Netvouz RawSugar Reddit scuttle Shadows Simpy Smarking Spurl TailRank Wists YahooMyWeb

Leave a Reply