WordPress Tip: Templating Posts vs Pages

Posted in Wordpress Tips
Tags: ,

Posts and pages have a lot in common, and although most themes will have separate templates for these, they rarely differ all that much.

First of all, as with every template that deals with the things between the header and footer, you need to include said header and footer. This is done with the get_header() and get_footer() template tags.

Second, you need the loop to output the appropriate content. This would be different posts or pages – just one, depending on the situation. The templates for posts and pages are almost identical, consisting of the loop, and then an inclusion of another template using get_template_part(), and calling for single.php (for posts) and page.php (for pages). These templates consist the actual output of the content, but the loop is what’s telling WordPress to go look for content.

The loop is used whenever content should be outputted.

The actual output of either of these types will consist of HTML markup with the dynamic parts swapped out for various template tags. This includes the post/page title, categories and tags if such are to be used and displayed, the author, and so on – as well as the actual content.

Most important will be the_title() and the_content(), for title and content, but adding post_class() to your wrapping element is also important if you want some default CSS classes added.

Reference: http://codex.wordpress.org/Stepping_Into_Templates

Leave a Reply

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

*