Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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:

http://skitch.com/zamoose/d12ns/about-us-delta-sigma-theta-sorority-inc-south-jersey-alumnae-chapter

But when I navigate to pages that exist under BuddyPress' control, I get the following:

http://skitch.com/zamoose/d12nu/delta-sigma-theta-sorority-inc-south-jersey-alumnae-chapter

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?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

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:

if( bp_current_component() ){

...or, if we want to detect when we're NOT in a BuddyPress area, the inverse:

if( !bp_current_component() ){

Easy peasy.

So, in total, the code looks like this:

if( !bp_current_component() ){
    if ( is_page() ) {
        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" ) ) { 
            echo '<ul id="subnav">';
            wp_list_pages( "title_li=&child_of=$parent&echo=1" );
            echo '</ul>';
        }
    }
} else {
    echo '<ul id="subnav">';
    if ( is_user_logged_in() ){
        bp_get_loggedin_user_nav();         
    } else {
        bp_get_displayed_user_nav();
    }
    echo '</ul>';
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.