I’m trying to work sub-menus into my theme but am running into issues when navigating to BuddyPress pages (as opposed to standard WP pages, posts, etc.). Basically, what I want to do is have pages (where appropriate) display a sub menu, ala:
But when I navigate to pages that exist under BuddyPress’ control, I get the following:
I’m using the following to generate the sub-menu:
if (is_page()) {
global $wp_query;
if( empty($wp_query->post->post_parent) ) {
$parent = $wp_query->post->ID;
} else {
$parent = $wp_query->post->post_parent;
}
if(wp_list_pages("title_li=&child_of=$parent&echo=0" )) { ?>
<ul id="subnav">
<?php
wp_list_pages("title_li=&child_of=$parent&echo=1" );
?>
</ul>
<?php
}
}
Where am I going astray?
EDIT: I received a direct, easy answer from the folks over on the BuddyPress forums:
There is a template tag called bp_current_component() that returns a boolean. So, in short, to tell if we’re currently in a BuddyPress-ized section of the site, we simply call:
…or, if we want to detect when we’re NOT in a BuddyPress area, the inverse:
Easy peasy.
So, in total, the code looks like this: