Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am developing a WordPress template (or rather trying to) and need a bit of help/advice.

I have a template that consists of a header (inc nav), footer, main content area.

The main content area has two columns - the left column for a sub-menu and the right for content, as demonstrated by the crude diagram linked below. The right content area contains several more rows and columns which are different for most pages of the site - some have a series of rows and columns, others have a single row/column.

I'm wondering what the best way to create these templates are - do I create several templates, each accommodating the different structure or is there a better way? The only thing that is inconsistent between each page is the right hand column (purple area), and it seems a shame to duplicate the entire page into a new template just because of this one inconsistent area, especially more so if I have different styles within the content area.

I've added a screenshot to demonstrate two possible layouts!

Edit: I don't have the required 10 reputation to post images unfortunately, so image is located here:

enter image description here

share|improve this question
    
Have a look at the Template Hierarchy. How will you determine what template gets loaded? Category, tags, ...? –  Pat J Jul 5 '13 at 16:02

1 Answer 1

up vote 3 down vote accepted

Your consistent/common areas are:

  • Header (Including nav)
  • Footer
  • Sidebar

So you can easily make them accordingly to:

  • header.php - get_header();
  • footer.php - get_footer();
  • sidebar.php - get_sidebar();

And the right content area, as it is inconsistent, so it can be separated into a different page as:

  • content.php (general template)
  • content-double.php (template 1)
  • content-page.php (template 2)
  • etc.

And to include them just put the following code accordingly:

<?php get_template_part('content', ''); ?>
<?php get_template_part('content', 'double'); ?>
<?php get_template_part('content', 'page'); ?>

In this way you can part your template into various particles and can include them where necessary. Any question is highly recommended with thanks. :)

share|improve this answer
    
my index.php template contains the three includes for header, footer and sidebar. I see what you mean about separating the inconsistent areas into includes, thank you for the suggestion. I suppose my next question would be that if I used content-double.php twice on my site but need to change only an image in one of the columns, would I need to create two versions of content-double one for each image? –  Goonyan Harir Jul 5 '13 at 19:29
    
You can put the minor changes into a single file with conditional tags: if ( is_page( $page ) ) (Reference here)... –  Mayeenul Islam Jul 5 '13 at 19:38
1  
I honestly would upvote you for all the help you've provided, but I need 15 reputation sigh I'm marking this question as answered. Hopefully this will help others :) –  Goonyan Harir Jul 5 '13 at 19:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.