Skip to:
Content
Pages
Categories
Search
Top
Bottom

Alternate Stylesheets for different sections


  • michaelmarian
    Participant

    @michaelmarian

    Buddypress 1.2 and WordPressMU 2.9.1

    In my Buddypress child theme, I want to have different CSS for different sections like the Member profile. Perhaps I want to have a slightly different head graphic as well.

    I have copied the header.php to my child theme and have attempted to use if statements along with Template tags but to no effect.


    <?php if( bp_is_front_page() ){ ?>
    <link rel='stylesheet' href='wp-content/themes/coffeehouse/large-masthead.css' type='text/css' media='screen' />
    <?php } ?>

    <?php if(bp_is_group_members() ){ ?>
    <link rel='stylesheet' href='../wp-content/themes/coffeehouse/large-masthead.css' type='text/css' media='screen' />
    <?php } ?>

Viewing 11 replies - 1 through 11 (of 11 total)
  • for each css element you modify, you have to put it with the ” !important ” tag, because the core css have it, and you can not override without it too…


    michaelmarian
    Participant

    @michaelmarian

    Sorry. The first if statement does work but the template tag “bp_is_group_members()” does not. Nor do most of the template tags do not work.


    michaelmarian
    Participant

    @michaelmarian

    Thanks Nexia, The trick I’m looking for is in how to identify in the head which page I’m now on and to use and if statement to load something additional. For the main pages like Activity, Groups, Forums, I can use the page slugs in my if statement successfully. Just not in the sub sections.

    The code you’re looking for already exists in header.php… in the navigation bar section. It’s used for navigation tab highlighting… i.e… adding a class like “current” or whatever to the LI tags. Just copy/paste and modify.


    Bowe
    Participant

    @bowromir

    Mmm very original.. I’ve currently done this by modifying the templates and changing divs, but this is a better approach me thinks! Nice :)


    @mercime
    Participant

    @mercime

    Check out different CSS for posts and pages – http://digwp.com/2010/02/custom-css-per-post/


    Boone Gorges
    Keymaster

    @boonebgorges

    You could also just use body classes and put all styles in the same stylesheet.

    @Boone: Yah… actually… I do that all the time. Usually just for the odd tweak tho’… something I want to hide on a .home page or whatever.


    michaelmarian
    Participant

    @michaelmarian

    I also used this for identifying top level navigation.

    <?php if ( bp_is_page( BP_FORUMS_SLUG ) ) : ?>

    Problem for me is when you get into the Member sub navigation. I looked at your tab highlighting and agree that would also work. But I don’t see anything in the head that deals with the subsection pages.

    So I’m almost there. I’m looking at mercime’s link know to see how they are doing it.


    Mike Pratt
    Participant

    @mikepratt

    I think you are making more work for yourself than necesary. Andy has included specific classes in the Body class (as david alluded to) and you can specify styling for each page class that way, you cna also double up classes where you want consistency and no php will be required.


    @mercime
    Participant

    @mercime

    @Michaelmarian, For the Members subsection, easiest way is as Boone Gorges mentioned using body classes: e.g. Member’s Profile page use selector body.profile; Member’s Blog Page use selector body.my-blogs; Member’s Message Page use selector body.messages; etc.

    However, if you still want to use conditional statements see

    https://codex.buddypress.org/developer-docs/conditional-template-tags/

    Thing is, locate_template array did not work for me in all the different incarnations of custom child themes I made before so this method might help you too

    <?php
    if (bp_is_profile_component()) {
    include ('mystuff1.php');
    }
    elseif (bp_is_activity_component()) {
    include ('mystuff2.php');
    }
    elseif (bp_is_friends_component()) {
    include ('mystuff3.php');
    }
    else {
    include ('mystuff4.php');
    }
    ?>

    – For more specificity you could probably add – && bp_is_page(‘members’) – or whatever slug you used

    – Add wp_reset_query(); right after the opening <?php if this query is placed latter part of the page or add the reset just before ?> if placed near top of the page.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Alternate Stylesheets for different sections’ is closed to new replies.
Skip to toolbar