U23r
U23r

Reputation: 1703

How to show different menu on sidebar for each page

I have two different pages, called "Lab" and "Services". The "Lab" page uses a custom template page. The "Services" page shows 8 options of service, for each service it opens a different page. For example:

Lab Page Menu: (the menu I want to show on sidebar)

 - Item 1
 - Item 2
 - Item 3

Service page: (the page have this services and inside each service have some options)

- Service 1
-- Option 1.1
-- Option 1.2
-- Option 1.3
- Service 2
-- Option 2.1
-- Option 2.2
- Service 3
-- Option 3.1

Services menu would be:

- Option 1.1
- Option 1.2
- Option 1.3
- Option 2.1
[...]

So, when I click on "lab" page it would show the first menu (Item 1, Item 2...) and when I click on a service from "Services" page it would show the second menu (Option 1.1, Option 1.2 ...).

Both, Lab and Services pages uses a costume page template. Is there a way to specify this for sidebar show the different menu for each page?

My sidebar.php code:

<aside id="secondary" class="col-xs-12 col-sm-4" role="complementary">

        <?php do_action( 'before_sidebar' ); ?>
        <br><br><br>

        <?php if ( ! dynamic_sidebar( 'sidebar-1' ) ) : ?>

            <aside id="search" class="widget widget_search">
                <?php get_search_form(); ?>
            </aside>

            <aside id="archives" class="widget">
                <h1 class="widget-title"><?php _e( 'Archives', 'codex-coder' ); ?></h1>
                <ul>
                    <?php wp_get_archives( array( 'type' => 'monthly' ) ); ?>
                </ul>
            </aside>

            <aside id="meta" class="widget">
                <h1 class="widget-title"><?php _e( 'Meta', 'codex-coder' ); ?></h1>
                <ul>
                    <?php wp_register(); ?>
                    <li><?php wp_loginout(); ?></li>
                    <?php wp_meta(); ?>
                </ul>
            </aside>

        <?php endif; // end sidebar widget area ?>
    </aside><!-- #secondary -->

Upvotes: 0

Views: 854

Answers (2)

Peter
Peter

Reputation: 732

How about using the plugin "Display Widgets"(https://wordpress.org/plugins/display-widgets/screenshots/)?

With this plugin, you can show/hide certain (sidebar) widgets for each page. There is also another good plugin: Widget Logic (https://wordpress.org/plugins/widget-logic/)

Upvotes: 1

Tyler Cook
Tyler Cook

Reputation: 31

This may not be exactly what you are looking for, but I found this bit of code a while back somewhere that I used on a project, and it was very helpful. If I remember right you should be able to change the depth and it will do the Option 1.1 Option 1.2 etc...

<?php
  if($post->post_parent)
  $children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
  else
  $children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0&depth=1");
  if ($children) { ?>
  <ul>
  <?php echo $children; ?>
  <?php echo strip_tags ($children, '<a>, <hr>'); ?>
  </ul>
 <?php } ?>

http://bit.ly/1O4B15N is the page I used this on. So everything under the sidebar header was generated by this bit of code.

Upvotes: 1

Related Questions