First time I have used stack-overflow, please forgive me if I make a faux pas.
I am new to php, and am currently building my first WordPress Theme. I want to have several separate sections of the website with a side-bar menu that displays links only to the other pages in the section you are in. For example if you are viewing post 1 of section A the side menu would display links to posts 2, 3, and 4 of section A. The menu would be the same on all posts of section A. Section B would have a different menu displaying it’s posts. The site will require about 25-30 different sections.
I was hoping to do this with Categories, but am certainly open to other options. I have attempted this a few different ways to no success. I feel this should be simple, and I am just missing something basic.
I think my problem is calling the information necessary I started it as:
<?php if (is_category('tanzania')) : ?>
<?php wp_nav_menu(array(
'theme_location' => 'tanzania-menu'
)) ?>
<?php elseif (is_category('safrica')) : ?>
<?php wp_nav_menu(array(
'theme_location' => 'safrica-menu'
))
<?php else : print('Nope.'); ?>
<?php endif; ?>
This did not work at all (something I am sure is super obvious to you all). It displays each menu properly but only at the category overview page. Once you click on a link in the menu it takes you to the post’s perma-url and the menu vanishes. I figured out that this is because the in_category only sees pages in the /category/ directory, but am unsure how to fix it.
The other issue is having my sidebar.php be so long. Using the above method I basically had a huge switch ~80 lines long. I am not sure if that is bad, but it seems… unwise. Everytime I tried to shrink it down, I ended up with it not working at all.
Thank you for your help with this, WP has been quite the learning curve.
It’s not working the way you want because once you leave the category page the rules no longer apply.
You could create a whole bunch of templates – one for each group of pages. In the template you define a custom sidebar into which you add the custom menus. But this is really clunky and time consuming.
Do you really, really need to make things so complicated for your visitors? They will get very lost and bewildered trying to find their way around the site if you keep changing the navigation form page to page.