• Hi There,

    I’m creating a site with about 20 pages and I have a typical sidebar for each page. I’m using a default template page that applies to every page beyond the front page. I created a sidebar.php and added a few items, I guess we’ll call them modules, for the sidebars. For example, I have a Mission statement, a banner for IT Hosting, a little promo image, etc. I basically have more items\module than I want to put on each page. I only want to use about three of them depending on which page they are on. I don’t want them randomly displayed.

    What’s the best way to selectively choose what I want to add to each sidebar of every page I have? I’m asking for the sake of best practices. I could create a customer template php file for each page and add what I want to the sidebar, but that seems a bit tedious for WordPress. I’m hoping there’s an easier, more efficient, solution.

    Let me know your thoughts, thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try using the is_page() conditional?
    https://codex.www.ads-software.com/Conditional_Tags

    If your header is adding body_classes() to the body tag, you can easily target things depending on what page they’re on. You could basically have the same sidebar for each page, hiding what should not be seen on that particular page.

    For example, you might have four panels, one for each page, called .panel1, .panel2, .panel3, .panel4 and the css would initially have display: none;

    Each of the panels can then be targeted using the page’s unique body class (.pageid-10, .pageid-12, .pageid-14, etc) with display: block;

    So, the CSS would be:

    .panel1, .panel2, .panel3, .panel4 { display: none; }
    .pageid-10 .panel1 { display: block; }
    .pageid-12 .panel2 { display: block; }
    .pageid-14 .panel3 { display: block; }
    .pageid-16 .panel4 { display: block; }

    It’s not necessarily the most efficient way of doing it as the code for each panel will be generated on every page, but it is certainly easier from a programming point of view (ie, you don’t need any complicated <?php if/then/else ?> constructions!

    Hope that helps

    Peter

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Different sidebar contents for many pages – Best Practices Question’ is closed to new replies.