Skip to:
Content
Pages
Categories
Search
Top
Bottom

At my wit\'s end with custom theming …

  • @madyogi

    Participant

    I need some help guys and gals …

    I am designing a custom theme, completely from scratch, for an install of WPMU, including BuddyPress. I’m running WPMU 2.8.4 right now and BP 1.1.1. What I’m trying to do doesn’t seem like it would be that hard. I’m just obviously not understanding the whole scope of what I need to know.

    I basically need to load specific information into header/footer/content areas of various pages (including, but not limited to archives, 404’s, single posts, pages, buddypress pages like profile, activity, etc). My strategy has been to create custom header and footer files for each necessary case, then use an if … elseif … else statement in the main header.php/footer.php files to include the appropriate content.

    While I seem to be able to get this work in many different occasions, blending the buddypress pages with the WPMU pages (particularly search, archive, and 404) has proven difficult. Apparently, BuddyPress pages like Profile, Activity, etc return true to the following WP Conditionals placed in my header.php – is_archive(), is_search(), and even is_404() if you can believe that.

    I know this is dragging on, but please stick with me if you can, because I am highly frustrated. To make matters more confusing, once we have included the header, in this case headerHome.php, I then run an if … elseif … else statement to determine which of the main menu tabs should be set to active, and it always shows correctly.

    I am totally befuddled by this. It seems that the two statements, which are essentially identical except for what info they return, should display the right content. Here are the two code examples:

    From header.php

    <?php

    if ( is_home() ) {
    include (TEMPLATEPATH . '/../ARHealthCareersFrameTheme/customHeaders/homeHeader.php');
    } elseif ( is_single() ) {
    include (TEMPLATEPATH . '/../ARHealthCareersFrameTheme/customHeaders/homeHeader.php');
    } elseif ( is_page(array ('Why We\'re Here', 'ahecs') ) ) {
    include (TEMPLATEPATH . '/../ARHealthCareersFrameTheme/customHeaders/homeHeader.php');
    } elseif ( is_archive ) {
    include (TEMPLATEPATH . '/../ARHealthCareersFrameTheme/customHeaders/homeHeader.php');
    } elseif ( is_search ) {
    include (TEMPLATEPATH . '/../ARHealthCareersFrameTheme/customHeaders/homeHeader.php');
    } elseif ( is_404 ) {
    include (TEMPLATEPATH . '/../ARHealthCareersFrameTheme/customHeaders/homeHeader.php');
    } else {
    include (TEMPLATEPATH . '/../ARHealthCareersFrameTheme/customHeaders/communityHeader.php');
    }

    ?>

    From this code, all BuddyPress pages display the homeHeader.php file. Curiously, however, if I remove the is_archive, is_search, and is_404 lines, communityHeader.php loads correctly.

    Here is the bit of code from homeHeader.php

    <?php
    if ( is_home() )
    $mainMenuTab=0;
    elseif ( is_single() )
    $mainMenuTab=0;
    elseif ( is_archive() )
    $mainMenuTab=0;
    elseif ( is_page(array ('Why We're Here', 'ahecs')) )
    $mainMenuTab=0;
    elseif ( is_search() )
    $mainMenuTab=0;
    elseif ( is_404() )
    $mainMenuTab=0;
    else
    $mainMenuTab=2;
    ?>

    So, with my original header.php file, all BuddyPress pages show homeHeader.php instead of communityHeader.php. However, the variable $mainMenuTab will be set to 2, which means the code atop homeHeader.php is performing as I would expect, but not the code inside the header.php file.

    Anyway, I know this is a lot to weed through, but I would greatly appreciate any thoughts you all might have as to why I am banging my head against the wall on this one. Things would be easier if the BuddyPress conditionals would perform as expected, but I have had no luck with the conditionals like bp_is_user_profile and others.

    Am I just going about this task in the wrong way? Do I not really have a sound understanding of how to accomplish this particular task? Or is something just screwy?

    Please help if you can.

Viewing 18 replies - 1 through 18 (of 18 total)
  • @djpaul

    Keymaster

    Try playing with bp_is_page() – i.e.

    if ( bp_is_page( BP_HOME_BLOG_SLUG ) ) { … }

    @takeo

    Participant

    Also… with regards to highlighting your tabs… those links should all be getting classes assigned via WordPress which you can then hook into to style (i.e… something like .current_page)

    @madyogi

    Participant

    Thanks to you both for the quick responses!

    @DJPaul – is there somewhere I can find all the parameters bp_is_page() will take? For example, I’m wondering if the profile page has a generic slug/parameter that will return true every time a bp profile page is being displayed. Same with any messages page, activity page, etc.

    @David – I’m actually using a script called Dynamic Drive tabs to display the main menu tabs and their submenus. With this script, as you roll over the various options, it will display the submenu divs. Then it defaults back to the current tab, which is set when you activate the menu via javascript. The $mainMenuTab variable is assigned an integer based on what type of page you’re on, then echoed in the javascript call. It’s working quite well for me so far.

    @johnjamesjacoby

    Keymaster

    I think you’re on the right track, but making it more complicated than it needs to be. If this is strictly for the home blog, you can try…

    bp_is_blog_page() which will return true anytime “/blog” is the current BP component.

    Check bp-core-templatetags.php for a complete list of all functions that will help you narrow down which BP page it is that your users are looking at.

    Then rather than check every other possible function, you can just check one or the other?

    @madyogi

    Participant

    I am essentially not using the blog function of BP at all, only the extended profiles, the wire, the activity, etc. That said, all pages are in essence the home blog of my WPMU install. So what I’m needing is to figure out if I’m (or one of my users) is looking at a BP component or not, then display the right stuff.

    Would it make sense to query the $bp global here? as in:

    ...
    } elseif ( $bp->current_component == profile ) {
    //include whatever corresponding content here
    }
    ...

    I’m not as up on my php as I should be. Is this a viable option?

    @xevo

    Participant

    In the codex template tags there are already is_ functions for the buddypress pages.

    https://codex.buddypress.org/developer-discussions/buddypress-template-tags/

    If that is what your looking for..

    @madyogi

    Participant

    Okay, so I think I’m getting somewhere. Dug through the bp-core-templatetags.php file and found the bp_current_component() tag. So I added the following to my header.php file:

    ...
    } elseif ( bp_current_component(profile) ) {
    include (TEMPLATEPATH . '/../ARHealthCareersFrameTheme/customHeaders/communityHeader.php');
    }

    This seems to work, but all the components are now giving the communityHeader.php file, not just a profile page. So the activity, messages, friends, etc pages are all returning true for this particular elseif statement. Is the parameter “profile” meaningful in this case, or is this just checking to see if there is a bp_current_component or not? Alternatively, are all these pages (activity, messages, wire, etc) considered profile components?

    Thanks again so much for all your help.

    @madyogi

    Participant

    @Xevo – I’ve actually tried several of those, but I can’t get them to perform as I would expect. Not sure why, but bp_is_user_profile returns true even when no profile component is being viewed.

    @madyogi

    Participant

    Alas, my excitement continues to be dissuaded.

    The statement … if ( bp_current_component(profile) ) … seems to be acting just like bp_is_user_profile … they both return true on every page load. The only reason this seemed to work earlier is because I placed the if ( is_home () ) condition above it, so that overrode it until I went to, say a blog archive page (again, there is only one blog on my page … I’m only interested in the profile/wire/activity/friend functions of BP.

    Though it’s still a bit puzzling that the if … elseif … else statement in my actual homeHeader.php file functions as expected in virtually every circumstance, setting the proper menu tab setting.

    @johnjamesjacoby

    Keymaster

    madyogi, you’re on the right track but you’re still grasping at straws.

    Take a deep breath and look at how all the functions in bp-core-templatetags.php work. There should be a function there for every core area of BP.

    P.S. – It’s “wicks” end, like a candle that’s about to burn out. :D

    @madyogi

    Participant

    @John James Jacoby – It seems like the bp_is_blog_page() is returning true under every circumstance, even if I’m in my root directory, not the /blog directory. I would love to be able to “just check one or the other,” as you say, but it seems like the wp conditionals like is_archive, is_home, etc. are competing with the bp_is_… conditionals. I am just looking for a way to check if a buddypress component such as profile, messages, activity, wire, etc is being viewed. If this is the case, display one header, otherwise, display another.

    @madyogi

    Participant

    Right – wick’s end … HA!

    @xevo

    Participant

    Check the “bp-core-templatetags.php” line 1590 to 1717.

    Looks like they use more then one check to see if your on a certain component of buddypress. Hope it helps.

    @madyogi

    Participant

    I think I’ve got a lock on this, thanks to everyone’s help.

    @Xevo – It does seem like I ought to be able to query the body classes, or at least use them for styling purposes. I actually started a bit earlier in the file, at about line 1342, finding bp_is_profile_component(). With this I was able to isolate the profile page from all others. This seems to be functioning properly for now, but it still looks like I’m going to have to query for each type of buddypress component. I have not yet seen anything that functions like a bp_is_component(), combining all these together. Doesn’t seem that difficult to do in the next core, if it doesn’t already exist. It would just be nice to have one tag that would check for any of the is_ functions between line 1250 and 1587 in bp-core-templatetags.php, and return true if any of the returns true.

    Perhaps one function like this does exist already?

    Thanks again for everyone’s input.

    @xevo

    Participant

    I doubt the function exists, because if it did, they’d probably use it themselves.. :)

    But yes, it might be a nice extra. Perhaps add it on the trac?

    @madyogi

    Participant

    So, this is noteworthy – I went through and added all 7 of the top-level is_ function’s found in bp-core-templatetags.php between lines 1250 and 1330 or so. This does seem to fix all my problems except those regarding the wire component. For some reason my wire pages are still showing homeHeader.php instead of communityHeader.php.

    This configuration does seem to cascade, insofar as profile > edit still shows communityHeader.php without having to reference bp_is_profile_edit specifically.

    Anyway, more later.

    @madyogi

    Participant

    Alright, I’m super-close now it seems, but I still need a bit of advice. It seems that what I have so far works in every case but search pages and 404 pages.

    The way it looks to me, every bp_is_…_component() tag returns true for all wordpress is_search and is_404 queries. So, two questions:

    1) What is it about all the bp pages that trigger the 404 and search conditionals in wordpress?

    and

    2) How might I differentiate the two cases?

    @madyogi

    Participant

    Okay, by adjusting my statements to say:

    if (  bp_is_whatever_component() && !bp_is_blog_page() ) {
    //do whatever
    }

    They are functioning as I would expect, except for the wire component, which still is returning false in all cases. I have no messages on my wire, could that be causing this?

    My question now has to do with shortening my code. I now have a string of 7 if … elseif statements to query all bp_components, including communityHeader.php if any return true, before my else, which includes homeHeader.php in all other cases. How might I go about reducing my string of 7 to one?

Viewing 18 replies - 1 through 18 (of 18 total)
  • The topic ‘At my wit\'s end with custom theming …’ is closed to new replies.
Skip to toolbar