The Official UpThemes Blog
The best place to find WordPress tutorials, theme teasers, company news and much more.

Monthly Archives: July 2011

When building out a custom “Blog” section for your WordPress site, sometimes it’s easiest to create a custom page template that you can customize that allows you to set the page location (such as http://upthemes.com/blog), as well as your very own title and description that are displayed at the top of the blog section.

Step 1. Copy index.php to tpl_blog.php

To start, copy your index.php file from your current theme and rename the copied file tpl_blog.php. The reason for this is to get an exact copy of the theme functions and HTML structure from your current theme and to create a page template that will eventually be selectable from the ‘Page Template’ dropdown.

Step 2. Create Page Template ID

In your new file tpl_blog.php, you need to add a special comment to the top of the file that WordPress will recognize as a custom template.

Simply add that to the very top of your page and now WordPress will recognize it in the Edit Page screen sidebar.

3. Use Custom Query for Posts

Place this below the get_header() template tag:

This will override the current page query with a custom query for 10 paginated blog posts. Since we’re using query_posts(), we don’t need to generate a new custom WP_Query to store the custom query.

4. Add Navigational Links for Pagination

Below your post loop, add some links for pagination like so:

This should be between the endwhile; and endif; sections of code in your theme.

5. Reset the Query

Once you’ve output all your posts and navigation, you can use wp_reset_query() to reset the query_posts() results that you created earlier. In lamens terms, you’ve now reset the query to what it was before you called query_posts().

6. Putting it all together

Here’s a completed page template that utilizes everything described above with additional markup and includes the loop:


If you want to add fancy overlays for images and HTML on the front-end of your template, there’s no reason to use wp_enqueue_script and wp_enqueue_style. All you need in your functions file is: add_thickbox();

That’s it! Boom, you’re theme just got awesome with one line of code.