0

Hi there I have a few questions on adding different sidebar texts to sidebars per page.

On one part of my site, I have pages dedicated to individual animals. I have figured out how to change the layout to include a left sidebar to these pages (registered the sidebar, called the sidebar).

The intended use for this sidebar is to provide "Quick Facts" for each animal.

I set up the first animal page just fine with the Quick Facts (Text Widget) in the left sidebar. Then I moved onto the second animal page and, of course, the same sidebar came up with the same information (Quick Facts and other things such as a thumbnail of the region the animal lives in).

I plan on having many different animal pages (100+) so I don't want to register a new sidebar for each one of I don't have to.

I am looking for alternatives in how to deal with it. I rather not use a pre-programmed widget or plugin to help, if I can do this by coding within the files instead. I will accept suggestions for plugins or widgets if that is all you can think of, but please explain how to use it and not just "here try this one". I am learning to be a web developer so learning how to do this from the ground up would be most helpful.

I will not link the site because it is not secure. It should be fairly easy to visualize the problem but here is a dummy page for a fictional animal to help: Animal Factoid Page

Once again:

  • Left sidebar
  • Text Widget with a list of "Quick Facts" on each animal
  • For each animal page, 100+ pages (not posts)

The main problem here being how to most efficiently do this for upwards of 100 pages that are all in the same format?

Thanks for your time!

Edit:

I have tried Widget Logic Plugin. I can get the Text Widget to show up for an individual page. The problem I foresee is that I will have 100+ Text Widgets showing in that particular sidebar. Is this how people do it?

Side Idea:

I could also scrap the idea of a left sidebar with widgets in favor of somehow coding the page to have a left column. The only way I know how to do this is to make divs during the Page Creation and float the "left column div" next to the "main content div". This means I would have to do this with each and every page, but that doesn't seem too hard just tedious. When I initially went to research how to make "columns" in wordpress most of them were written to include another sidebar as a column instead, which I felt was silly but went along with it anyways. If anyone has any input on this, please let me know!

Sorry for the wide range of questions, but I want to cover all my bases on potentially what to do. Thanks!

2

You're looking for custom fields. Widgets are, generally, meant to be used for far more static content.

Pages have custom fields enabled by default. You might not see them in the editor because I think they're also hidden by default. Click 'Screen Options' to make sure they're turned on.

When you create the custom field, you'll give it a key and a value. Use the same key for each page. In your template (or sidebar) you can get the custom field like this:

<?php
    var $meta = get_post_meta($post->id, "your-key", true);

    if(!empty($meta)): 
?>
    <aside>
        <?php echo $meta; ?>
    </aside>

<?php endif; ?>

There are plenty of great plugins out there for dealing with custom fields. One benefit almost every plugin offers is making sure that the correct meta key (or keys) is always used. It's easy to flub it when dealing with lots of content. Pods, Advanced Custom Fields and CMB2 are three very popular ones, all with a slightly different take on it.

  • Thank you for the advice! I will definitely try using the custom fields tonight. It has been something I haven't tampered with yet while learning wordpress. – Nimara Nov 11 '15 at 22:22

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.