Skip to:
Content
Pages
Categories
Search
Top
Bottom

another problem when it's a single item

  • Avatar of Grosbouff
    grosbouff
    Participant

    @grosbouff

    Hi; I got another problem while trying to handle a single item.

    First, this is the code which ‘handles’ my navigation (checks if we are in our profile, in another profile, in the directory or viewing a single item)

    if ($bp->current_component == $bp->classifieds->slug) { //we are in classifieds
    if (bp_is_home()) { //we are in our profile
    ...
    }elseif (($bp->displayed_user->id) && (!bp_is_home())) {//we are in someone else profile
    ...
    }else if ( $bp->is_single_item ) {
    // We are viewing a single classified, so set up the
    // classified navigation menu using the $classified_obj global.

    /* When in a single classified, the first action is bumped down one because of the
    classified name, so we need to adjust this and set the classified name to current_item. */
    $bp->current_item = $bp->current_action;
    $bp->current_action = $bp->action_variables[0];
    array_shift($bp->action_variables);

    $classified_link = $bp->root_domain . '/' . $bp->classifieds->slug . '/' . $classified_obj->slug . '/';

    // Reset the existing subnav items
    bp_core_reset_subnav_items($bp->classifieds->slug);

    bp_core_add_nav_default( $bp->classifieds->slug, 'classifieds_screen_classified_home', 'home' );
    bp_core_add_subnav_item( $bp->classifieds->slug, 'home', __('Home', 'buddypress'), $classified_link, 'classifieds_screen_classified_home', 'classified-home' );
    // If the user is a classified mod or more, then show the classified admin nav item */
    }else { //we are in directory
    $bp->is_directory = true;
    ...
    }

    }
    }

    So if we are viewing a single item; this is the function called :

    function classifieds_screen_classified_home() {
    global $bp;

    echo "function classifieds_screen_classified_home";exit;

    if ( isset($_GET['new']) ) {
    // Delete classified request notifications for the user
    }

    do_action( 'classifieds_screen_classified_home' );

    bp_core_load_template( apply_filters( 'classifieds_template_classified_home', 'classifieds2/classified-home' ) );

    }

    Here’s my problem :

    If I go to /classifieds/classified1234

    It goes to the function classifieds_screen_classified_home() and runs the code echo “function classifieds_screen_classified_home”; exit; ).

    But If I go to /classifieds/classified1234/watch

    It does not !

    What is strange is that in my code above; if I put

    echo “single item”;exit;

    at the top or at the bottom inside my statement

    }else if ( $bp->is_single_item ) {

    and that I try

    /classifieds/classified1234 or /classifieds/classified1234/watch, it does echoes “single item” then exit.

    So I don’t understand why after it doesn’t run the function classifieds_screen_classified_home.

    Any idea ?

    Thanks a LOT.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    I think you are relying on $bp->is_single_item for your url parsing. I’m not sure that var gets set to what you expect it to be set to. In the url signature you mention above:

    /classifieds/classified1234

    The $bp->current_component is ‘classifieds’ the $bp->current_action would be ‘classified1234′ and $bp->action_var’s would be an empty array. Adding the ‘watch’ to the end of the url such as:

    /classifieds/classified1234/watch

    would make the $bp->action_var[0] be ‘watch’.

    It might be better to know the url signature you are expecting and trap for that pattern. Like:

    if ($bp->current_component == $bp->classifieds->slug && $bp->current_action){

    .. figure out if the user is in their profile or someone else’s profile ..

    }

    if ($bp->current_component == $bp->classifieds->slug && $bp->current_action

    && ‘watch’ == $bp->action_vars[0]){

    .. ‘watch’ the classified specified in $bp->current_action ..

    }

    Avatar of Grosbouff
    grosbouff
    Participant

    @grosbouff

    Here’s what I get when I print $bp in the code that ‘handles’ the navigation :

    /classifieds/classified1234

    [current_component] => classifieds [current_action] => [action_variables] => Array ( ) [current_item] => test11919 [is_single_item] => 1

    /classifieds/classified1234/watch

    [current_component] => classifieds [current_action] => watch [action_variables] => Array ( ) [current_item] => test11919 [is_single_item] => 1

    When I print $bp in classifieds_screen_classified_home() :

    /classifieds/classified1234

    [current_component] => classifieds [current_action] => home [action_variables] => Array ( ) [current_item] => test11919 [is_single_item] => 1

    /classifieds/classified1234/watch goes to profile page.

    I still do not understand why classifieds_screen_classified_home isn’t “fired” when adding /watch since it still respond to the statement }else if ( $bp->is_single_item ) {.

    I would rather prefer not do things like

    if ($bp->current_component == $bp->classifieds->slug && $bp->current_action
    && 'watch' == $bp->action_vars[0]){

    since it makes my code more complex.

    I would prefer use

    if (‘watch’ == $bp->action_vars[0]) inside my function classifieds_screen_classified_home…

    Possible ?

    Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    Are you in the member profile, or just trying to trap url signatures in the root? Is the url something like mysite.org/classifieds/otherstuff or mysite.org/members/me/classifieds? What the nav code sees and gets as $bp vars can be completely different than what is seen in the member profile area, the group area or just the root.

    This is a confusing area of bp so it helps to know where you are working.

    It looks like $bp->is_single gets detected after the trap for ‘is the user in their own profile or somebody elses profile’. Those two cases cover all cases so $bp->is_single doesn’t even get considered. If I read your skeleton code right.

    Avatar of Grosbouff
    grosbouff
    Participant

    @grosbouff

    i’m in the root (wordpress-mu/classifieds/classified1234)…

    Avatar of Grosbouff
    grosbouff
    Participant

    @grosbouff

    So what I would success to have is to detect if

    -we are on a profile page

    –logged-in user profile

    –or other

    -we are on a single classified page (which should be shown inside its author profile)

    -we are in the directory (lists the classifieds in the root)

    complete code here for the nav : http://pastie.org/545457

    I adapted the code from the skeleton example & from the bp-groups plugin.

    What is also confusing for me is that there is a code for a single classified starting on line 4 ; but there is also code for the single classified starting at line 52.

    Maybe is there a way to simplify this.

    Thanks a lot for your help ! I appreciate..

    PS : template for directory does not load either (line 92 with statement starting at line 84)

    Avatar of Grosbouff
    grosbouff
    Participant

    @grosbouff

    Burt, I updated my code to fit more like the bp-groups plugin.

    I put two echoes somewhere in the code :

    echo “classifieds_screen_directory”; (line 103)

    echo “classifieds_screen_single”; (line 118)

    which do show when I go to

    wmpu/classifieds

    wmpu/classifieds/test1234.

    But their templates still not loading… The paths are okay.

    Could you have a look ? Thanks, it here : http://pastie.org/546228

Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.