Different Ways To Display Content in WordPress
Written by Stefan Vervoort on September 19, 2008While I was developing the new theme for DivitoDesign (which will knock on your doorstep soon enough), I was facing some issues about how to display content with WordPress as I am not going for the traditional look with this theme, but with a Magazine look.
The power of magazines or magazine looking blogs are the loads of information that can be displayed. If you want to run a successful magazine, you need to focus on writing content and not on manually add the entries to your theme. An important factor for a magazine is there how you automatize the process of displaying content.
We will use the WordPress template tag query_posts();. Remember this tag only works in the WP loop. You can find a version of the WP loop I use below:
<?php query_posts(); ?> <?php while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <div class="entry"><?php the_excerpt(); ?></div> </div> <?php endwhile; ?>
Parameters for query_posts()
We are going to give the query_posts() tag some parameters on how to operate. Some of those parameters are given below:
- cat > the category you would like to choose
- showposts > the number of entries you would like to show
- offset > number of the entry you don’t want to display
- orderby > order the entries by author, category or anything else
- tag > select entries by tag
- More parameters can be found at WordPress
Display Featured Post
In a magazine theme you might want your visitors to focus on the featured entry. You need to add your specific entry to a category named featured.
If you want to show one featured entry in the loop, change:
<?php query_posts(); ?>
to:
<?php query_posts("cat=featured&showposts=1"); ?>
Latest Post
If you want to select the latest entry, this parameter will get you there:
<?php query_posts("showposts=1"); ?>
The other posts
If we have selected the latest entry from the database, you might want to show the other (older) items as well expect the ‘latest’ item you have already shown. Here’s the query:
<?php query_posts("showposts=5&offset=1"); ?>
Exclude Category(s) or tag(s)
If you want to display all entries, expect the ones from a certain category or tag you need to get to the ID of the category or tag first (wp-admin>manage>tags/categories):
<?php query_posts("cat=-1"); ?> <?php query_posts("category__not_in=2,3,4"); ?> <?php query_posts("tag=-2"); ?>
Show posts by Author
It is easy to make a page that shows all the posts a specific author wrote for your blog:
<?php query_posts("author=2"); ?> // Author's ID (wp-admin>users) <?php query_posts("author_name=stefan"); ?>
Examples
These examples are just a couple things I have learned lately and it’s not everything that’s out there. You should remember there is alot more you can do with WordPress Template tags, as well as with the query_posts() attribute.
For more examples visit the query_posts codex page.


Great tutorial getting at the guts of a Wordpress template. I’m just getting in to creating and modifying Wordpress templates, so this post will come in handy as a reference. I’m going to Digg it!
I’m also planning a restructure of information over at my site, and like you, I’m using Wordpress as my weapon of choice.
There does seem to be a shortage of worked examples on using custom methods (i.e. not the traditional loop) to pull content onto a page, so thanks for this!
@Bottlecap & Stuart – Great this guide helped you, and thanks for your comments!
Thanks Stefan! Just what I was looking for today.
Thanks for this tutorial. I have been wondering for a long time how to do this. I will use this information. Thanks again.
[...] Different Ways to Display Content in Wordpress [...]
[...] Different Ways to Display Content in WordPress – Devito Design does a great job of sharing a bunch of different ways to display your blogs content in WordPress. [...]
[...] Source: http://www.divitodesign.com [...]
[...] Different Ways to Display Content in WordPress – Devito Design does a great job of sharing a bunch of different ways to display your blogs content in WordPress. [...]
nice work out tahnk for this info
[...] Different Ways To Display Content in Wordpress [...]
Thanks for those comments and links my friends!
[...] http://www.divitodesign.com/2008/09/different-ways-to-display-content-in-wordpress/ — php display [...]
[...] lot of other combinations which can be used. I found a great resource for this information over here at an article written by divitodesign. Also interesting is a read up in the wordpress codex over [...]
This was a usefull info. Thank you for the list. I’m getting to know the WP one day and will sure use these methods.
This was good info cause I’m trying to fix a new blog to show posts from different authors. Is there a way to show the posts from oldest first and new one last? That would be a great way to read a blog from the beginning and move towards the end. Like a diary from the start
[...] Different Ways To Display Content in Wordpress » DivitoDesign Awesome ways to display content in wordpress (tags: tutorials tutorial wordpress code) [...]
[...] Different Ways To Display Content in Wordpress (tags: wordpress hacks tutorials) [...]
[...] Different Ways To Display Content in WordPress [...]