Useful WordPress Template Tags for Theme Development

Template tags can be used in your wordpress theme to display information dynamically or retrieving information about your wordpress blog. In this post we will show you some easy and useful wordpress template tag that you can use in your theme.

Template tags are codes that instructs wordpress “get” something/information for example to getting your wordpress blog description, title, category. The great part of using template tags is you can avoid using plugins, which can certainly make your website faster. Before we get started you should have the basic knoweldge of PHP, since wordpress is built on it. Also, just to make sure you must wrap all with codes with <?php (all codes here) ?> .

Listing WordPress Categories

This tag is used to retrieve all the categories in your blog. You can also pass different parameters to exclude some categories or other functions. The simplest way to pull your category is :
[cc escaped=”true”]

The result you will get it is

Lets, pass some parameters to make it more useful and clean.
[cc escaped=”true” ]
wp_list_categories(‘orderby=name&title_li=’ . __(‘Categories’) . ” );
This tell wordpress to pull up the categories, order them by name, put the in a ordered list with a h3 title tag. You join parameters or arguments by using the “&” between them;

You can also customize the look by using the CSS. Usually default CSS
for wordpress categories is “categories”. So you would style it by
[cc lang=”css”]
li.categories a{
If you wanted to include or exclude categories or some other modifications you can do so by following codes
[cc escaped=”true”]
/* For including certain categories to the list */
/* For excluding certain categories from the list */
/* Will show rss links right next to the category*/
/* Recently updated category and showing how many post on that category*/
wp_list_categories(‘show_last_update=1&show_count=1’ );

Further Reading

Getting the Tag Cloud

Showing wordpress cloud tag is very simple. Just specify the size of the most and least tagged post and how do you want to order it by.
[cc escaped=”true” ]

This code displays 30 most tagged post, the least tagged font size is 14px and the most tagged font size is 30px and they are ordered by name.

Here are some other parameters you can use:
[cc escaped=”true”]
/* Display your category as tag cloud */
wp_tag_cloud( array( ‘taxonomy’ => ‘category’ ) )
/* For including excluding tags (the tags with that term_id0 from the cloud */
/* Display your tag cloud as list */
wp_tag_cloud(‘format=list&smallest=15&largest=40’ );

Further Reading

List WordPress Pages

Listing how many pages you have is pretty much same as category. Therefore, I won’t go into too much details

[cc escaped=”true”]

/* Listing all pages*/
/* Exclude pages */
wp_list_pages(‘exclude=17,38’ );
/* Order by date */

Further Reading

List Popular Post Without Plugin

This method actually uses  wpdb class function. As Bin-Blog shows points out here , an easy way to list the popular post is by using wpdb class function to get the result for most commented posts.
[cc escaped=”true”]
$popular_posts = $wpdb->get_results(“SELECT id,post_title FROM {$wpdb->prefix}posts ORDER BY comment_count DESC LIMIT 0,10”);
foreach($popular_posts as $post) {
print “<li><a href='”. get_permalink($post->id) .”‘>”.$post->post_title.”</a></li>\n”;

This code with gives the following by result:

The only problem with this technique it does not specify post or page. It gives you result for both pages and post. If you look at the above screenshot the Theme is a page. So, how do we get around it. A simple solution : using mysql query to specify post_type in wordpress database  like this: WHERE post_type = ‘post’. This will only output most commented post.
Here is the modified version:
[cc escaped=”true”]

$popular_posts = $wpdb->get_results(“SELECT id, post_title FROM {$wpdb->prefix}posts WHERE post_type = ‘post’ ORDER BY comment_count DESC LIMIT 0,10”);

foreach($popular_posts as $post) {
print “<li><a href='”. get_permalink($post->id) .”‘>”.$post->post_title.”</a></li>\n”;

Get the Recently Published Post

WordPress  get_post template post is very useful tag. Many useful information can be retrieved by using the tag. Again we are going use  wordpress mysql database to inquire the latest post and print them in a list .

[cc escaped=”true”]

$postslist = get_posts(‘numberposts=10&orderby=post_date’);
echo”<h3> Recently Pubished</h3>”;
foreach(  $postslist as $post ) {echo “<li><a href='”. get_permalink($post->id) .”‘>”.$post->post_title.”</a></li>\n”;}


$postlist variable gets the latest 10 posts and order them by the recent date by using post_date table. We have added an echo for the title ( 2nd line). You can customize it however you want. Here is the result you should get:

Customizing WordPress Archives

Many websites like to customize their archives differently such as as by month, by year and etc. This allows the reader to browse however they want. That’s where wp_get_archives tag comes in. We will show you couple of ways you can list your archives:

List all the post alphabetically

[cc escaped=”true”]



List last twelve month post and Show the amount of post each month

[cc escaped=”true”]


If you want to organize your wordpress archive into columns check out Jeff Star’s post. Jeff explains in details how to do it.

Further Reading

That’s it for now. You should get familiar with all other wordpress templates tags if you are looking to get into wordpress theme development or customizing your own theme.

  1. Jodi
    June 23, 2010

    I’m developing my first WordPress site, so this is very timely and useful – Thanks!

  2. June 23, 2010

    Nice list. There’s an error in the title “wordrpress”.

  3. June 23, 2010

    great post! you spelled ‘wordpress’ wrong in your title, just fyi

  4. June 23, 2010

    thanks guys! I just fixed the title.

  5. Alexander
    June 23, 2010

    Hi! I find this very useful as I’m currently looking into wp theme development. However i think you got this part wrong:

    ” /* For excluding certain categories from the list */
    wp_list_categories(‘orderby=name&include=3,4’); ”

    and that it should be:

    ” /* For excluding certain categories from the list */
    wp_list_categories(‘orderby=name&exclude=3,4’); ”

    Anyways, great post and big thanks!

  6. June 23, 2010

    Great titles!~ I can use some code in my theme.

  7. June 26, 2010

    GREAT! Could you also include tags for the new features in 3.0?

  8. June 29, 2010

    Hey, great tips.. thank you for sharing.

  9. July 17, 2010

    It’s not a new tag for us but it’s useful, thank you.

  10. August 3, 2010

    THanks for this great tuto.

    How can i display all title of a categorie, exemple all title of categorie shopping ?
    i put this code ” wp_list_categories(‘shopping’);” thanks for your reply

    sorry fot my bad english i’m frenc

  11. August 7, 2010

    useful list 🙂
    as new guy in WP, I’d prefer minimized plugin use.
    btw, any body know how to display tag clouds by post status. just imagine it can be done with query post (should be – need more read Codex). any idea how to make it happen ? 😀

    thank you

  12. August 11, 2010

    WordPress is great, it makes somethings easy for others.

  13. August 11, 2010

    Useful WordPress Template Tags for Theme Development.

  14. August 11, 2010

    Showing wordpress cloud tag is very simple. Just specify the size of the most and least tagged post and how do you want to order it by.

  15. August 11, 2010

    I’ve used a template of wordpress for my blog, it is interest.

  16. August 11, 2010

    Thanks alot for the usefull information. “Get the Recently Published Post” was exactly what I needed.

  17. August 15, 2010

    Hey, great tips.. thank you for sharing.

  18. August 23, 2010

    like this

  19. September 13, 2010

    wordpress template is useful. But it is difficult to use, I think.

  20. October 7, 2010

    Its awesome man, got many helpful tricks.

  21. January 10, 2011

    Thanks for this handy collection of code.You can find more in

  22. April 20, 2011

    Thank you so much I have been very helpful!

Leave a Reply

Your email address will not be published. Required fields are marked *

Win a Free Copy of Designer’s Marketing Secret