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.

6 Responses to “How to use custom page template in WordPress themes”

  1. Gravatar

    ?php if (! is_page('forum') || is_page('google-search') ) get_sidebar(); ?

    One more try.

  2. Gravatar

    I can't get my post to show the code I put in my footer.php. So I am trying again here it is.

    -""-

  3. Gravatar

    Awesome this is the post I had been waiting for and it works well for the forum. I am also trying to get google custom search for adsense to work so the results would display in a separate page. I took what you had given on the forum which works for me as displayed here http://www.greenfitnessworld.com/forum. However if you go to http://www.greenfitnessworld.com/google-search the side bars get shifted over for some reason. I created a new template like this for google search.

    In the footer.php I added this.

    It is probably something I am doing wrong with the OR statement. If someone could respond that would be great.

  4. Gravatar

    To Ray above me here...

    The "Headspace" plugin says it has the ability to assign different theme styles to pages. You might take a look and see if it will work for you.

    Or, you could call a separate style sheet in your custom template. Like this:
    @import "http://your-site/name-of-style.css";

    Hope that helps!

    Pablo

  5. Gravatar

    Ne radi ovo...

  6. Gravatar

    Like what you are doing with this and want to use it, but I don't see the option when editing (or creating) a page to use a different template. Is there something else I have to turn on to do that?

    Thanks,
    R

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="">