0

I'm very familiar creating page templates in WP and for this project I really just have one page template with an option to switch the sidebar from the right side to the left side. The problem is that I would hate to have all of that duplicate code in both templates especially since I'll just be swapping css classes on the two elements.

Options:

  • 2 separate Page templates
  • Custom fields
  • Custom taxonomies

I'm thinking that having a custom taxonomy might be the best solution. The client would see a small box on the right side of the page titled Visual Options and there would be a checkbox for Sidebar on right. It is intuitive and it is DRY.

Is there something else I didn't consider?

1

Don't use custom page templates for structural layout changes.

Use custom post metadata instead, and then output conditional CSS rules (or even custom HTML markup, though that's probably not necessary here) based on the value of the custom post metadata.

  • I was thinking about using custom fields (custom post meta data) but they seems a little less user friendly. Your thoughts? – BFTrick Aug 29 '12 at 18:38
  • Actually, using post custom metadata fits your description perfectly: "The client would see a small box on the right side of the page titled Visual Options and there would be a checkbox for Sidebar on right." That exactly describes the implementation of a post custom meta box. – Chip Bennett Aug 29 '12 at 18:50
  • Bennet My apologies. I thought custom fields & custom post meta data were the same thing. This is exactly what I was looking for! Thanks. – BFTrick Aug 30 '12 at 14:50
0

You can use conditional tags.

Example: Your index.php file in your currently active WordPress theme might look like this:

<?php
get_header();

if(is_page()){
    if(is_front_page()){
        // Home page
    } elseif(is_page('About Us')){
        // About Us page
    } else{
        // Any page
    }
} elseif(is_404()){
    // Error not found page
}

get_footer();
?>
  • This would work but there are a lot of pages and I would rather save this info in the DB rather than in the code. – BFTrick Aug 29 '12 at 18:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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