Having different sidebar content for MANY pages?

You could dynamically register sidebars. When you register sidebars, you could query for all of your animal pages, loop over all pages, and register a unique sidebar for each page. Adding a page would automatically create a sidebar for it.

However – that’s a lot of sidebars. For something tightly coupled with the page content, I would rather handle it with custom fields via a custom meta box that contained your pre-defined field(s).

As for why your use of post meta disturbed the layout of your site, it’s probably just an issue of markup / styling. The simplest course may be to get the layout looking right with a sidebar and text widget, then copy the markup that’s generated when you view the page, and use that as the wrapper markup for you custom fields. Looking at your template above, widgets will appear as <li>s within a <ul>, so try that when adding your post meta:

<div class="cryptid-sidebar-left">
    <ul class="cryptid-sidebar-widgets-left">
        <?php
        $meta = get_post_meta(get_the_ID(), "your-key", true);
        if( !empty($meta) ): 
        ?>
        <li>
            <?php echo $meta; ?>
        </li>
        <?php
        endif;
        ?>
    </ul>
</div>

Leave a Comment