Helping you Build Your Own Social Network!

Faster, better and easier!

Conditional Tag for BP-generated Pages

(10 posts) (2 voices)

  1. WPMU and BP trunk versions. Using custom child theme of 1.2 bp-default.
    WPMU for this project is used as CMS and BP is installed in blog_id_1
    My sitewide main navigation is from blog_id_1 and generated from wp_list_pages. I've added BP items in a subnav enclosed in following conditional tag to appear only in BP-generated pages in main site, like so:

    <?php if (is_home() || is_page('12') ||  || is_page('16')  || is_page('25')  || is_page('29') ) { } else { ?>
    <div id="subnavz">
    <ul id="nav2">
    <li<?php if ( is_page( '151' ) ) : ?> class="selected"<?php endif; ?>><a href="http://mysite.com/member/" title="<?php _e( 'Clubhouse', 'buddypress' ) ?>"><?php _e( 'Clubhouse', 'buddypress' ) ?></a></li>
    <li<?php if ( bp_is_page( BP_HOME_BLOG_SLUG ) || bp_is_blog_page() && !is_front_page() ) : ?> class="selected"<?php endif; ?>><a href="<?php echo site_url() ?>/<?php echo BP_HOME_BLOG_SLUG ?>" title="<?php _e( 'Blog', 'buddypress' ) ?>"><?php _e( 'Blog', 'buddypress' ) ?></a></li>
    <li>etc </li>
    <li>etc </li>
    <li>etc </li>
    <?php endif; ?>
    <?php do_action( 'bp_nav_items' ); ?>
    </ul>
    </div><!-- subnavz end-->
    <?php } ?>

    #1: The code above is working to a certain extent (see #2 below). But I need a more elegant solution to above because I'll be adding much more Pages in main site and I foresee the major task of adding each Page (is_page('etc') ) to exclude above :-)

    I've been looking for the conditional tag to include ALL BP items, just can't find it or overlooking something, so that I can just code something like

    <?php if (is_BP_Generated_Pages_Only) : ?>
    <div id="subnavz">
    <ul id="nav2">
    <li<?php if ( is_page( '151' ) ) : ?> class="selected"<?php endif; ?>><a href="http://mysite.com/member/" title="<?php _e( 'Clubhouse', 'buddypress' ) ?>"><?php _e( 'Clubhouse', 'buddypress' ) ?></a></li>
    <li<?php if ( bp_is_page( BP_HOME_BLOG_SLUG ) || bp_is_blog_page() && !is_front_page() ) : ?> class="selected"<?php endif; ?>><a href="<?php echo site_url() ?>/<?php echo BP_HOME_BLOG_SLUG ?>" title="<?php _e( 'Blog', 'buddypress' ) ?>"><?php _e( 'Blog', 'buddypress' ) ?></a></li>
    <li>etc </li>
    <li>etc </li>
    <li>etc </li>
    <?php endif; ?>
    <?php do_action( 'bp_nav_items' ); ?>
    </ul>
    </div><!-- subnavz end-->
    <?php endif; ?>

    so that subnavz will show only when in the BP-generated-page.

    #2. Re first code I posted above. The code shows correct "selected" class in WPMU sites except when with BP-enabled WPMU site like this one...

    a. I am in the first subnavz link, "Clubhouse" (page_151), the "selected" class is applied for both "Clubhouse" and "Blog" (the second link) - BAD

    Note: Clubhouse (page_151) is a page-template with code for sitewide Activities and I have it in the main navigation as well with same slug (member) but different page title "Members" (page_151 also)
    i.e. http://mysite.com/member/ = "Members" link in main navigation and "Clubhouse" link in sub-navigation.
    When someone clicks on the Members(page_151) link in main navigation, it opens the subnavigation with Clubhouse(page_151) in first link.

    b. When I click on "Blog" link, the subnavz disappears (BAD!) but when I click on the blog's post permalink, I get the subnavz back with "Blog" link has "selected" class (GOOD).

    I've been looking at this for the past few hours and I need new set of eyes to see what's making this stumble in BP-enabled site :-)

    Thanks.

    P.S. I've tried removing is_frontpage from second link code, "Blog" but still the #2a and #2b behaviors persist.

    Posted 2 years ago #
  2. My bad. Edit.

    Posted 2 years ago #
  3. hi mercime
    Thanks for posting the question.
    First of all, a work around for testing whether you are On buddypress generated pages or wpmu posts/pages.

    try replacing
    <?php if (is_BP_Generated_Pages_Only) : ?>

    with
    <?php if (!bp_is_blog_page()) : ?>

    The function bp_is_blog_page() will return true for the home page/all the blog pages/posts of the main site.
    but It will return false for all the bp components,activation page,registration page, so It gives us an easy workaround :)

    Now taking a look at you other question, I will be posting a reply soon again.

    Thanks
    Brajesh

    Posted 2 years ago #
  4. Now I need a small clarification, before tackling the actual problem.
    Since you said you are using wpmu as CMS, so do you want the secondary navigation to appear on blog posts/blog home but not on the pages(The page as in wordpress pages) and the WPMU Home Page.

    Is that correct ?

    Posted 2 years ago #
  5. Just clarifying, do you want the secondary navigation to appear on all BP generated pages,blog,blog posts,"member/clubhouse" page but not on wpmu home page and other wpmu pages.

    Is that right, please correct me.

    Posted 2 years ago #
  6. Hi Brajesh. My WPMU as CMS is set up with main navigation wp_list_pages which includes links e.g.
    - Home Page (home.php customized with image slideshow, and not the one from bp-default)
    - About Us
    - Mountains Climbed
    - Members (http://mysite.com/member/ - which is the same link of ClubHouse, the 1st link in Secondary Navigation and using page-template with the SiteWide Activity Code)
    - Guestbook
    - Contact Us , etc etc.

    All member sub-blogs are using switch_to blog_id_1 for main navigation and do not need the secondary navigation. I made two custom child themes of 1.2 bp-default theme - one for the main site and one for ALL sub-blogs.

    The secondary navigation should contain that Clubhouse link which is http://mysite.com/member/ which has the sitewide activity code and all the BP generated pages.

    I tried using the code you gave <?php if (!bp_is_blog_page()) : ?> and it works well for Groups, Forums, Members but not "ClubHouse" or "Blog" because the secondary navigation disappears on both links.

    What I'm trying to do is that because my theme's home.php is set up to do something else than the sitewide activity that's in bp-default theme, I'm making it up by including the sitewide activity code in "ClubHouse" Page I created with page-template published using http://mysite.com/member/ which would appear in home page of secondary navigation and as a link in main navigation.

    Posted 2 years ago #
  7. hi mercime
    Thanks for the message.
    I am a little bit confused yet, but I hope, this will solve your problem.

    First of all, I don't remember a way to distinguish programatically between the site home page and Main blog(site.com/blog) after bp is installed, because is_home() and is_front_page() will return true for both of them.

    So here is a custom function to specifically find, we are on site.com/blog or not. Put it in bp-custom.php

    /*check if we are at main blog's home page, that is example.com/blog*/
    function bpdev_is_blog_home(){
              global $bp;
              if($bp->current_component==BP_HOME_BLOG_SLUG&&empty($bp->current_action)&&empty($bp->action_variables))
              return true;
              else
              return false;
          }

    Now, Since we want the secondary navigation to appear on club house and Blog link, we will use this

    <?php
    /*if this is a club house page, or /blog page or any of the BP generated NON blog page, show thse secondary navigation*/
    
    if(is_page('151')||bpdev_is_blog_home()||!bp_is_blog_page()){
    //code fo secondary navigation
    }

    Please Note, this will show secondary navigation on all BP components(profile,forum,groups,directory,register,activation etc page),Club House page(your custom page) and Blog Home for main blog(your site.com/blog) but It will not display secondary navigation for Site Home page/WPMU blog posts(for main site as well as sub blogs) and any other wpmu pages.
    So, If you want to use it in this way, It will work.

    In case you want to show secondary navigation ,even on the blog posts of the main site, you will have to modify it slightly.

    PS: I will be online around next 5-6 hours from now, so let me know if you want other variations. I will be glad to modify it :)

    Posted 2 years ago #
  8. Brajesh, thank you for taking the time from your very busy schedule to look into this further. I suspected it would turn out to be a special function but kept on trying to find a way to resolve it without one. Sorry if I don't make sense at this time. It will all be made clear when I show you the site, simple but worth it :-)

    I will test the codes now and report back in a little while.

    P.S. I'm thinking of using the style/images you had for your BP-Nicey for the #content area of all my sub-blogs made with customized child theme from bp-sn-parent as it goes well with the styles I made my theme. Will credit you for that in my style.css, ok?

    Posted 2 years ago #
  9. you are most welcome :)
    I look forward to see the site soon.

    No problem with the time. I am glad I am able to help you and I will do my best to assist further.
    I am a little bit tight on schedule because of the gallery and a few themes coming soon. Gallery has taken much time than anticipated. It is working, but the Interface, I am not liking, so I am still working on it before making publicly available(you know, they call it first impression matters :))

    you are most welcome to use all/any part of images/themes/css you want. It is all up to you to give credit or not. yes, I will highly appreciate it if you are going to give the credit :)

    Please try the code and let me know. I look forward to your further post.

    Thanks
    Brajesh

    Posted 2 years ago #
  10. I have now incorporated the style/images from the #content area of BP-Nicey (so easily, thanks) into the default theme for all sub-blogs - child theme based on bp-sn-parent. I haven't started on adapting it yet to the #content area for the main site's child theme (based this time on new bp-default) because the layout's different and more complicated. Will do that this coming weekend most probably.

    Re Gallery Plugin. 10-4, take your time. I know it could only be beta at this stage and when you release it because of the many changes in BP and WPMU codebases. I know what you mean by first impressions - it counts a lot :-)

    I placed the function you gave me in my bp-default child theme's functions.php for the main site, instead of bp-custom.php, because I wanted to code to work only in the main site.

    For the conditional tag, I added that to my template and added is_single, etc. to the mix so that the secondary navigation will appear on main site's single post pages, archives, etc. as well :-)
    <?php if(is_page('151')||is_single()||is_archive||is_category||bpdev_is_blog_home()||!bp_is_blog_page()){ ?>
    and it works.

    At this time, when I click on Sitewide Main Nav, Members link http://mysite.com/member/ - the secondary navigation (used in main site only) shows selected states for both "Clubhouse" (http://mysite.com/member) and "Blog" links. But if you click on "Blog" link in secondary navigation, only "Blog" link is selected now, unlike before in my first post where if I click on "Blog", the "Clubhouse" link was also in "selected" state.

    Finding a fix to disabling both links selected at same time can be done later, perhaps when I open the site so you can see what I mean :-) I appreciate that you are "flying blind" at this time and what you've coded even at that, is already awesome! What this current code does for me at the very least is save me a lot of time whenever I add on Pages for the CMS part of the main site as I continue development.

    Cheers.

    Posted 2 years ago #

Reply

You must log in to post.