How can I detect whether a BuddyPress page is active from within my theme?

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

Read More

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?

Related posts

Leave a Reply

1 comment

  1. 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>';
    }