How to use custom page template in WordPress themes
A reader recently suggested I should expand my forum page to show without the sidebar, so it's more easier to follow.
Since the forum is actually a page where the forums is rendered by a plugin, it is possible to select a template for the page (this is a feature of WordPress, found on edit page screen). Page template allows you to specify a custom look for your page, for example without restrictions in width like I need.
Page template I created looks like this:
<?php
/*
Template Name: Forum
*/get_header();
if ( have_posts() ) while ( have_posts() ) { the_post(); the_content(); }
get_footer();
?>
You first specify the template name, in this case I used Forum. I then call he header of the theme (get_header) to render the upper menu with navigation.
After is the WordPress 'loop' which will print out my page.
At the end I call the footer code (get_footer). Since my theme actually calls the sidebar in the footer I had to add this code to the footer.php:
<?php if (! is_page('forum') ) get_sidebar(); ?>
The code says do not display the sidebar if the page is forum.
The last thing is to select the forum template for the page and the magic happens - my WordPress forum is now full width.
About this entry
You’re currently reading “How to use custom page template in WordPress themes,” an entry on Vladimir Prelovac site, published: Thursday, November 20th, 2008
-
Check more articles like this:
- How to Add Google Custom Search to your Blog
- Ask the WordPress Guru, Q&A #1
- Optimize your WordPress page loading times with a simple tweak
-
Write a comment.
-
Get my newsletter, RSS feed or twitter.
Hi! My name is Vladimir Prelovac. I am a computer engineer by profession and an adventurer by state of mind.
9 comments, newest first
Jump to main menu | Jump to comment form | Toggle comments