-1

I'm a newbie, using WP 3.6.

On a custom theme I've put a subpages menu on a sidebar using "wp_list_pages".

On the same sidebar under the subpages menu I'm trying to add some WP built-in widgets (recent posts, calendar, etc...).

As soon as I add a widget and refresh the page, the subpages menu disappears...

I've googled a lot but I haven't found any tutorial on this specific topic.

I don't want to use any plugin, I prefer to code it by myself.

Do I have to convert the subpages menu code into a widget?

  • 1
    Post your relevant code please. – s_ha_dum Aug 25 '13 at 17:37
  • When you say "the subpages menu disappears" are you saying that you checked the page source and the markup that was displaying the menu is not there or are you saying you only can no longer see it displayed in the browser? – Charles Clarkson Aug 25 '13 at 20:01
  • @ Charles Clarkson I haven't checked the page source... but yes, the menu is no longer displayed in the browser. – Roberto Aug 26 '13 at 8:43
  • @ s_ha_dum Here's the code: <!--<?php if($post->post_parent) { $children = wp_list_pages('sort_column=menu_order&title_li=&child_of='.$post->post_parent.'&echo=0'); $titlenamer = get_the_title($post->post_parent); } else { $children = wp_list_pages('sort_column=menu_order&title_li=&child_of='.$post->ID.'&echo=0'); $titlenamer = get_the_title($post->ID); } if ($children) { ?> <h2> <?php echo $titlenamer; ?> </h2> <ul> <?php echo $children; ?> </ul> <?php } ?> – Roberto Aug 26 '13 at 8:54
1

If I'm understainding you correctly, you've hardcoded the wp_list_pages() function in to the widgetized area of the theme's sidebar, and then, when you add a widget using WordPress' back end Appearance->Widgets then you no longer see the output of the wp_list_pages() function?

If that's the case, then I think we've found your problem. If code exists in a template's widgetized area it will only display if no widgets have been assigned to the area. As soon as a widget is assigned it will override any code that is inside the widgetized area. Think of it as being a kind of built-in if statement that says

if ( no widgets ) {
    Do the code I have written here;
} else {
    Do the widget code;
}

Probably your best bet would be to create a custom menu under Appearance->Menus and then use the built-in Custom Menu widget that WordPress provides already.

  • @ TaishiZiyi Yes, it's exactly as you said! As I have several pages I will have to create a custom menu for each page... I was wondering if it was possible to create a widget for the subpages menu and then put it into the widget areas of each page. – Roberto Aug 26 '13 at 8:50
  • Sure. You can absolutely create a custom widget to do this. In fact, if the wp_list_pages function is doing what you want, then you would just need to create the widget in your functions.php file. There is a lot of code involved, but here is a link to a great tutorial for how to do it: wp.tutsplus.com/tutorials/creative-coding/… – TaishiZiyi Aug 27 '13 at 21:53

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.