Skip to:
Content
Pages
Categories
Search
Top
Bottom

Conditional statement to differentiate between profile and activity.

  • @enderpal444

    Participant

    I need to have a different sidebar for the activity pages than the profile. I already have a sidebar.php that uses conditional statements for single, page, home, etc. How can I setup an if statement for just the profile pages and another for all activity pages?

Viewing 8 replies - 1 through 8 (of 8 total)
  • @enderpal444

    Participant

    Bump. I really need a solution for this please.

    @enderpal444

    Participant

    I’ve tried every conditional tag listed on the codex but nothing works. Would really be nice if one of the many people on here who know the answer to this question would take the time to leave an answer. Here is what Im using to trying an pull a specific sidebar to the profile page.

    `<?php
    if (is_single()){
    include(STYLESHEETPATH.’/sidebar-single.php’);}
    elseif (is_page()){
    include(STYLESHEETPATH.’/sidebar-index.php’);}
    elseif (is_category(‘fame-game’)){
    include(STYLESHEETPATH.’/sidebar-fame-game.php’);}
    elseif (bp_is_user_profile()){
    include(STYLESHEETPATH.’/sidebar_act.php’);}
    else {
    include(STYLESHEETPATH.’/sidebar-index.php’);}
    ?>`

    @hnla

    Participant

    profile/account seems to be a difficult one to easily check for.

    `bp_current_action()` returns a value for members account screens and for group screens so you could use that with a check for a null or empty string along with a check to see whether you are on a groups page or groups component

    @enderpal444

    Participant

    I substituted bp_current_action() but that still calls the default sidebar for a profile. I searched all over for an answer but it’s like nobody has ever had a need to use different template parts for a profile than an activity page.

    @hnla

    Participant

    You seem to be approaching things from to different angles first post you suggest you are working in sidebar.php adding conditional blocks, my approach above would work to create a block that would only appear in sidebar.php if you were on /in a user account set of screens in that block you could set a new widget region if you wanted to add widgets from dashboard.

    I’m not sure what your approach above is in using those include statements – they’re not really the preferred method in WP, if you want to simply have a different sidebar for account screens why not simply create new file and replace the get_sidebar call with a named one get_sidebar(‘account’) in /members/single/home.php

    @enderpal444

    Participant

    I need to have a different sidebar for a profile page than an activity page and I dont see how to accomplish that by that method. The whole idea is that a profile page is more for learning about a member. My members post things and I want to show their own posts in a sidebar. But they are active on an activity page so I want to show posts of others since they don’t need to look at their own work.

    @enderpal444

    Participant

    Boone Gorges oon wordpress.stackoverflow.com figured it out. is_page() will return true on BP content, because BP (since 1.5) uses WP pages as its basis for display. So we changed it to this and now I have a sidebar only for profile pages.

    `<?php
    if (is_single()){
    include(STYLESHEETPATH.’/sidebar-single.php’);}
    elseif (is_page() && !bp_is_profile_component()){
    include(STYLESHEETPATH.’/sidebar-index.php’);}
    elseif (is_category(‘fame-game’)){
    include(STYLESHEETPATH.’/sidebar-fame-game.php’);}
    elseif (bp_is_profile_component()) {
    include(STYLESHEETPATH.’/sidebar-act.php’);}
    else {
    include(STYLESHEETPATH.’/sidebar-index.php’);}
    ?>`

    @hnla

    Participant

    Boone is a core developer of BP and posts on this BP support forum, can you post a link to the stackoverflow post for completeness and for others if they happen across this thread looking for same help.

    I didn’t and still don’t really get you requirement here or why the include function and not get_sidebar or template_parts but yes is_page() works on components and, as I clearly missed the point, if you just wanted to target actual profile screen then either of what you had or have should work.

    Glad it’s sorted though :)

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Conditional statement to differentiate between profile and activity.’ is closed to new replies.
Skip to toolbar