Understanding Content Types in WordPress

The three content types in WordPress by default are posts, pages, and comments. Each of these content types have their own unique features. Understanding their unique features will help you unleash the full power of WordPress and will give you a full featured blogging experience. There are other content types which can be added to WordPress via plugins.

Posts

Posts are the main content type of your WordPress blog. A post is one entry on you blog and is generally tied to one or more categories and a date. There could be five different posts on the same day with three different categories or there could be just one post in one category. The posts, by default, are shown on the home page of your blog chronologically.

The post is the content type which drives the content and direction of your blog as well as enables conversation by using comments on the post.

 

Template Tag To list post

The template tag query_posts ( $args ) is used to list WordPress posts.

There are a lot of arguments this template tags take in. To read a complete comprehensive list you can check the following link.

http://codex.WordPress.org/Template_Tags/query_posts

Generally the query_posts template tag is used in conjunction with what is called as The Loop

(http://codex.WordPress.org/The_Loop ) which is a simple loop going through each post which is returned as the output on query_posts . The code template is as below

A sample code from index.php is as below.

 

Some important tricks with query_posts

How to display posts on the index page from only a particular category?

Generally all the themes display all the posts in chronological order from your database. If you have to display posts from only one category (for example- Category ‘Projects’) you can do the following changes in the index.php file

And then use The Loop after that. This would display all the post under the category Project

post in a category

 

How to display post on the index page which has a particular tag?

To display all the post which has a particular tag (for example- Programming) you can make the following change in index.php

This would display all the post which has the tag as Programming

post in a tag

Also if one has to display post of a particular Author he can use the following

 

How to display only sticky post on home page?

You can post a sticky post using the option shown below

Make sticky post

The sticky post(s) are shown above the normal posts.

If one wants to show only the sticky posts (and no other posts) on the home page

then one should make the following change (in file index.php )

This would display post only which are marked as sticky on the home page

Sticky Post Display

Pages

As WordPress grew as a blogging platform there was more and more need for it to have features like a CMS as people started using WordPress as a complete site making software. Hence the functionality of adding pages was added in WordPress.

Pages are just static posts. They are stored in the same way in the databases as posts.

They can have comments just like posts and can also register pingbacks and trackbacks.

They differ from the posts in that they are not displayed chronologically like posts but can be stored as a tree structure where pages would be placed under other pages.

One could also have custom templates for pages.

 

Template Tag To list pages

The template tag wp_list_pages( $args ); is used to list WordPress pages  as links .

There are a lot of arguments this template tags take in. To read a complete comprehensive list you can check the following link.

http://codex.WordPress.org/Template_Tags/wp_list_pages

Following is a code snippet from the file sidebar.php

 

Some important tricks with wp_list_pages

Here I am going to discuss some small tricks you can do with this template tag to customize your blog according to your needs.

 

How to change the title of page list to something like ‘documents’?

Page list Title

To do this find the template tag wp_list_pages  in your theme . In the default theme it in the file  sidebar.php  and there replace the following line

with

Changed Page list Title

The argument title_li of the template tag  wp_list_pages  determines what will be the title of the group of pages displayed below it . The default is Pages. So by changing that parameter we can change the title to the group of pages.

 

How to change the order of list of pages displayed?

By default the list of the pages are sorted in ascending order on the page title as you see in the image below.

Page list order

So if I want to make the list of pages in descending order of page title then use the argument sort_order of wp_list_pages . So changing the code for wp_list_pages   as follows will sort the page list in descending order (in sidebar.php).

Changed Page list Order

The pages can also be sorted on some other column for e.g:- post_date

So if I want to sort the pages in descending order on their post date then I use the following parameters to the wp_list_pages

Page list order by date

 

How to remove a particular page from of list of pages displayed?

If I want to remove a particular page from the list of pages for e.g:- The page ‘Projects Done’ with page id as 3 I should make the following change in sidebar.php

which would remove the page ‘Projects Done ‘ from the list of pages displayed.

Remove particular page

Comments

Comments are the most exciting feature of WordPress. Comments when enabled build a community on the blog. Many times the most interesting content is in the comments rather than in the posts. WordPress has a robust commenting system, incorporating trackback, pingback and per-post commenting.

 

Template Tag To list Comments

The template tag wp_list_comments ( $args ); is used to list WordPress Comments .

There are a lot of arguments this template tags take in. To read a complete comprehensive list you can check the following link.

http://codex.WordPress.org/Template_Tags/wp_list_comments

This tag is found in the file comments.php following is the code snippet from it

 

Some important tricks with wp_list_comments

How to reverse the order of the comments displayed on a page?

By default the comments are displayed in ascending order of date. So the oldest comment is displayed first and then the newer comments below it as shown in the image below

Order of comments

But many times you want the latest comment on the post/page to display on the top which will help the reader to get the latest comment immediately.

This can be done by changing the template tag wp_list_comments which is generally in the file comments.php as follows

This reverses the comment order displaying the latest comment on top as shown below. By the way, WordPress dashboard also has option in dashboard-discussion settings to show new comments on top and break it in pages.

Reverse Order of comments

 

Template Tag To Show a Comment pop-up link

The template tag
comments_popup_link(‘zero’,’one’,’more’,’CSSclass’,’none’);

is used to show the Comment pop-up link .

There are a lot of arguments this template tags take in. To read a complete comprehensive list you can check the following link.

http://codex.WordPress.org/Template_Tags/comments_popup_link

This tag is found in generally in index.php , following is a code snippet from it

 

How to change the text of the Comments Pop Up link when there are no Comments?

Suppose a post does not have any comments on it as yet. In that a link would still be displayed for comments pop up and would generally have the text as ‘No Comments’

Comments pop up link

Suppose I want to change the text ‘No Comments’ to something like ‘Be The First To Comment’. In that case I can make the following change to the call to template tag comments_popup_link as follows

This would change the text of the Comments pop up link to ‘’Be The First To Comment’

Changed comments pop up link

 

How to hide the Comments pop-up link if comments are closed on certain posts?

Sometimes on some post the comments are closed. Hence showing the Comments pop-up link next to it is not a good design for you blog ( as when that link would be clicked it would display on the next page that comments are closed on this post )

Hence if we have to show the Comments pop up link only if comments are open on a post make the following changes before comments_popup_link() in the index.php file

This would show the comments pop-up link on post which has comments open and wont show comments pop up link where comments are closed. See image below

Removed Comment Pop up link

Categories

Though this is not a content type this is a very important part of your WordPress blog. Categories help to organize your post. One way a person can read your post (and the way they are by default displayed on your blog ) is reading or surfing it chronologically. Category helps to organize your post not only in the sequence you post them but helps you to categorize logically similar post together. This would help a new reader of your blog who comes in late to your blog party to go through the post of different categories together.

 

Template Tag To list Categories

The template tag wp_list_categories( $args ); is used to list WordPress categories  as links .

There are a lot of arguments this template tags take in. To read a complete comprehensive list you can check the following link.

http://codex.WordPress.org/Template_Tags/wp_list_categories

Following is a code snippet from the file sidebar.php

 

Some important tricks with wp_list_categories

Here I am going to discuss some small tricks you can do with this template tag to customize your blog according to your needs.

 

How to show or hide the post counts under a category shown next to each category?

Whether to display the number of post under each category next to the category in the list is controlled by the parameter show_count to the template tag wp_list_categories .

If show_count=1 the number of post in each category are shown.

Category with count

Category with out count

 

How can I limit the number of categories in wp_list_categories?

One can limit the number of categories as the output of wp_list_categories .

This is particularly helpful in case you have many categories but want to display a few in the sidebar.

The max number of categories displayed depends on the value of the argument ‘number’

of the template tag in wp_list_categories.

So if you want to set a max limit on the number of posts then you can use

This would display only 2 categories in the side bar.

Limited Categories

 

How can I remove a particular category from the list of categories?

If I want to remove a particular page from the list of pages for e.g.- The page ‘Projects ‘with page id as 3 I should make the following change in sidebar.php

which would remove the page ‘Projects ‘ from the list of categories displayed.

Removed Categories

Conclusion

These are the basic content types of WordPress and making small tweaks in how these are displayed to the user you blog can really stand out. These small changes can make the blog look good and ease your blog navigation. You do not have to use the WordPress default settings with the WordPress content types. You can make changes to how your blog looks and appears to your readers by making some changes as discussed in this post.

About the Author