How to Create Multiple Page Layouts Using One Page Template in WordPress

wordpressWe are using WordPress as a CMS for a client who needed a 3 column layout for all the pages except one. This one page needed a full width content without any sidebars. Instead of using a different template for this one page, I decided to use PHP conditionals..

First, set the div for the content, depending on which page is displayed. The page we are removing the sidebars for is “short-sale-listings-phoenix”. Don’t forget to set the styles in style.css.

<?php  // display full width content or normal width content for 2 sidebars
	if (is_page('short-sale-listings-phoenix')) { ?>
         // display full width content
	<div id="content-wide">
	<?php } else { ?>
        // display narrow width content for use with sidebars
	<div id="content">
    <?php } ?>

Second, add or remove the sidebars.

<?php  // display sidebar or not
	if (is_page('short-sale-listings-phoenix')) { ?>
        // display no sidebar
    <?php } else { ?>
       // display sidebar
    <?php get_sidebar(); ?>
<?php } ?>

<?php  // display sidebar or not
	if (is_page('short-sale-listings-phoenix')) { ?>
        // display no sidebar
    <?php } else { ?>
      // display sidebar
    <?php get_sidebar('right'); ?>
<?php } ?>

That’s it.

Resource: If you need more help, here is a great article by Darren Hoyt Multiple WordPress Page Layouts in One Single Template.

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Add to favorites
About Jeffrey Horen

I am the owner of Excelnet Media. We are a full service, one stop interactive web agency building extraordinary websites with extraordinary customer service for extraordinary clients.

Speak Your Mind

*