Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do I stop BP from overriding default parameters passed to the template loop?

  • @3sixty

    Participant

    How do I stop BP from overriding default parameters passed to the template loop?

    For example, on the Activity page, let’s say you want BP to “forget” the user’s last viewed parameter (like “My Forums” or “@user Mentions”) and go right back to All Members or My Friends every time you reload the page.

    I tried deleting the contents of ajax.php and global.js, and the overriding behavior still happens. Where do I look next?

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

    Participant

    Update: still not there, but I just realized that overriding global.js defeats the ajax page loading altogether. (My browser was loading a cached version of the page)

    So I’m guessing that something in global.js is responsible for overriding the default tab selection?

    @apeatling

    Keymaster

    You can add them in the template to force override (create a child theme and override activity/activity-loop.php):

    <?php if ( bp_has_activities( bp_ajax_querystring( 'activity' ) . '&scope=friends' ) ) : ?>

    @boonebgorges

    Keymaster

    Last-viewed pages are saved in a cookie. So if I set the filter on the activity stream to “Show Blog Comments”, a cookie to that effect is stored in my browser. Next time I load the page on the same browser, “Show Blog Comments” is shown.

    In global.js, I believe the function that handles this is bp_init_activity(). If you comment the call to this function out (around line 15 of global.js), it should stop the cookie from overriding your default settings.

    @3sixty

    Participant

    Last-viewed pages are saved in a cookie. So if I set the filter on the activity stream to “Show Blog Comments”, a cookie to that effect is stored in my browser. Next time I load the page on the same browser, “Show Blog Comments” is shown.

    In global.js, I believe the function that handles this is bp_init_activity(). If you comment the call to this function out (around line 15 of global.js), it should stop the cookie from overriding your default settings.

    This works! Thank you Boone.

    Andy’s approach is also a nice one because it preserves the cookie functionality if you want to use it elsewhere.

    @boonebgorges

    Keymaster

    Well duh, Andy is smarter than I am :)

    @3sixty

    Participant

    In global.js, I believe the function that handles this is bp_init_activity(). If you comment the call to this function out (around line 15 of global.js), it should stop the cookie from overriding your default settings.

    HOLD THE PHONE. Simply commenting out bp_init_activity() doesn’t work. Reloading the page resets the tab, but the content stays the same as the previous selected tab.

    Next, I will try Andy’s suggestion, but I don’t understand exactly what he is suggesting:

    You can add them in the template to force override (create a child theme and override activity/activity-loop.php):

    <?php if ( bp_has_activities( bp_ajax_querystring( ‘activity’ ) . ‘&scope=friends’ ) ) : ?>

    Posted 1 day ago #

    Is he suggesting that the child theme have different activity loop files for each navbar entry? So you would have

    /activity/activity-loop.php

    /activity/activity-loop-my-friends.php

    /activity/activity-loop-my-groups.php

    /activity/activity-loop-my-mentions.php

    And then maybe make the navbar links into HTML forms and call those loops conditionally based on which HTML form is clicked?

    @boonebgorges

    Keymaster

    I think Andy is assuming that you want Friends to be the default view for every kind of activity stream. If you change it in activity-loop.php, it’ll change for every instance of the activity stream. There’s no need to have different versions of activity-loop.php for different sections of the site, as bp_has_activities already does the work of figuring out which page you’re on.

    If you only want to default to the Friends view on certain pages, you could put in some conditional logic. Call the global $bp in your template and look for $bp->current_component, $bp->current_action, $bp->action_variables. Use these to sniff out which page you’re on, and use some if-statements so that you only add the ‘&scope=friends’ argument on pages where you want the default to be ‘friends’.

    @3sixty

    Participant

    I’m at a convenient but vaguely unsatisfying stopping point in this saga.

    I ended up nuking all the lovely AJAX buttons on the /activity page in favor of HTML form buttons like this one

    <li style="float:left;" <?php if ($_POST["activity-tab"] == "friends") { echo 'class="selected"'; }?>">
    <form action="" method="post">
    <input name="activity-tab" value="friends" type="hidden" />
    <input style="border:0px" type="submit" value="My Friends" />
    </form>
    </li>

    Then later include()ing a custom stream and resetting the $_POST value to empty:

    ...
    <?php if( $_POST["activity-tab"] == "friends" ) { $_POST["activity-tab"] = ""; include( 'activity-loop-friends.php' ); } ?>
    ...

    The ideal solution here would be to somehow rewrite the cookie/display functions in global.js to “forget” the user’s last selected tab, but I was not smart enough to figure that one out…

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘How do I stop BP from overriding default parameters passed to the template loop?’ is closed to new replies.
Skip to toolbar