Last week I gave an example of how to create a magazine style theme. This method allowed you to have a main post followed by a list of titles. This week I’ll explain how to separate these on the page so that you can have a far greater control over your layout.
The Latest Post
Rather than using the WordPress loop to display the latest post in full, we can use the get_posts() function to grab the latest post and display it in full. To do this we can use the following code:
[sourcecode language="php"]$myposts = get_posts(‘numberposts=1&orderby=post_date&orderby=DESC’);
foreach($myposts as $post) :
setup_postdata($post); ?>
Post tags that you usually use within the loop.The Remaining Posts
Then we need to pull out the remaining posts in a list using the WordPress loop, however we don’t want the first post as we’ve already displayed this. To prevent the first post being displayed we use the query_posts() function, which allows us to add in additional parameters and manipulate the output in the loop. The code we use for this is as follows:
query_posts('showposts=5&offset=1');
This will tell the loop to retrieve 5 posts after the first post. We then use the loop to display the posts in a list with the above code just before the loop starts:
[sourcecode language="php"]






Hi,
Thanks for this tip… I had another related query. See, I want to show the in archives the actual number of posts as per the wordpress reading settings (If I say, 5 there, I want 5 posts per page in the archives). However, on the homepage I want to show only 3. The problem for me is that the 'while (have_posts())…loop still fetches 5. If I put a break logic after three, when I browse the previous pages, I loose 2 articles…
Pls help,
Ajith
I hope you can post more tips and techniques like these. They really interest people like me who are new to all these blogging business.
I have written an ebook about magazine style themes for wordpress which you can find on my blog. Good post Sarah
Ajith – Using the query_posts() function theoretically should work but it can have a tendency to break the next/previous navigation links. However it's worth trying first
<code>query_posts($query_string.'&posts_per_page=3');</code>
Put the above before your loop. If that doesn't work then post up in the Blogging Tips forums and we can take it further in there, as you may need to use a plugin instead.
Marian and Syed, thanks for the comments.