Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Different sidebar menus on each sub page. WordPress

I´ve had help converting a website I made in Dreamweaver to a wordpress theme. But there is still a function that is not working the way it was supposed to work. On each subpage I have a menu in left sidebar that is supposed to contain different pages on each page. That is working, but it is not a widget. He who made this for me created a template page for each sub page. So this is coded within the page.

I would of course prefer to use a widget instead. I found this one that I would like to work the way I want: [[LINK href=""]][[/LINK]].

But since the menu is already there, on each page where it should be. I "only" need the menu to fold out so you don´t from the beginning can see the sub pages. I guess this might be done making changes in "custommenu.php" which contains the stylesheet for that menu. But I´m not sure how, so I need help. But then again there might be more to it than that.

Unfortunately I am not able to get the help I need from the guy who made this for me. And I have a deadline next week.

If there is anyone who is willing to help me I can give you more detailed information in a mail if this is ok?

Hoping to get some help!

/ Lena

Answers (4)


Arnav Joy answers:

ok let me know what you need.

lapg comments:

Is it ok if I mail you a link to my server where the site is right now? So you can take a look at it there?

/ Lena

Arnav Joy comments:

yes that will be ok .


Daniel Yoen answers:

You can use conditional tags :

if(is_page( 'yourpage' ) ) {
//page sidebar menu
else if(is_page( 'yoursubpage' ) ) {
//subpage sidebar menu


Luis Abarca answers:

Try to check if page is a subpage and add or change the sidebar.

First, add some sidebars in your functions.php

register_sidebars(1, array(
'id' => 'sidebar-pages',
'name'=> 'Pages sidebar'

register_sidebars(1, array(
'id' => 'sidebar-subpages',
'name'=>'Subpages sidebar'

Second, call the sidebars from your sidebar.php or custommenu.php

$sidebar_name = 'sidebar-pages';

if ( ! isset( $post->post_parent ) || $post->post_parent <= 0 ) {
$sidebar_name = 'sidebar-subpages';

dynamic_sidebar ( $sidebar_name )


Jatin Soni answers:

To setup as a child page you need to create function as wordpress doesn't have such function to identify if the page is child page. In fact for the sidebar menu on child page this function will not work as you may need to pass the page id. So there is an easy way to do is by creating a page template and set all child page with the template.

I have create one page template by using twentyeleven theme. This is the logic and idea how you can get the sidebar for child page. You may need to style it to setup in to side.

First you need to register new nav menu in function.php. So place below code in to function.php

<!--[place this code into your function.php to register new menu]-->
register_nav_menus( array(
'sidebarmenu' => __( 'Sidebar Menu', 'themename' ),
) );

Below code is for the page template. You can name it something like tpl-childpage.php


Template Name: Submenu Page

get_header(); ?>

<div id="primary">
<div id="content" role="main">

<?php while ( have_posts() ) : the_post(); ?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->

<div class="entry-content">

<!--[add sidebar menu -- You need to style and set with the stylesheet]-->
<div id="side-menu">
<?php wp_nav_menu( array( 'theme_location' => 'sidebarmenu' ) ); ?>

<!--[this is your page content]-->
<div id="mycontent">
<?php the_content(); ?>
<?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', 'twentyeleven' ) . '</span>', 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<footer class="entry-meta">
<?php edit_post_link( __( 'Edit', 'twentyeleven' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</article><!-- #post-<?php the_ID(); ?> -->

<?php comments_template( '', true ); ?>

<?php endwhile; // end of the loop. ?>

</div><!-- #content -->
</div><!-- #primary -->

<?php get_footer(); ?>

You must use your default page.php to get the same structure and style.

Just let me know if you need any more help from me.

lapg comments:


I acually really need someone to give me the correct code to add to my page/pages. I am not a wordpress progammer so I need this help. I can add code of course myself if I know where to put it.

As I wrote in my initial question, everything but how the menu system works is in place. I can add the pages I want to all the sub pages, but the menu on the left sidebar does not function the way it is supposed to. I hope I can make the visual appearance changes myself in a css-file och custommenu.php.

I would like it to work as something like this:

But if I might give you the link to my local server so you can see how and what I mean, you might be able to help me? Can I send this to you in a private mail? Then it might be easier for you to take a look at it and see what I mean more exact?

/ Lena

Jatin Soni comments:

Sure you can send me the details and let me check if I can help you to fix this.

Please send me details in PM or at [email protected] or you can add me on skype as pixelandgrain