Home / Forums / DynamiX Support / custom link in menu

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts

  • Bruno Henriques
    Participant

    How do I setup a menu link pointing to my personal (the user that is logged in) buddypress activity stream?, like the bold part in the next link

    http://mysite/members/logged-in-user-id/activity/just-me/

    thanks in advance,

    bruno

    Andy
    Andy
    Keymaster

    Hi Bruno.

    I'm not sure – it maybe best asking on the BuddyPress forums instead to see what the members activiry URL would be. 


    Bruno Henriques
    Participant

    well, I've found this code:

    function bp_add_my_activity_link(){

      ?>

    <?php if (  bp_is_active( 'activity' )&&  is_user_logged_in() ) : ?>

    <li<?php if ( bp_is_page( BP_ACTIVITY_SLUG ) ) : ?> class="selected"<?php endif; ?>>

                <a href="<?php echo bp_loggedin_user_link(); ?><?php echo BP_ACTIVITY_SLUG ?>/" title="<?php _e( 'My Activity', 'buddypress' ) ?>"><?php _e( 'My Activity', 'buddypress' ) ?></a>

    </li>

    <?php endif; ?>

    <?php

    }

    ,that seems to take care of what I need, but I can't understand how can I add this link dinamically to your menu…. I'm adding this code to custom-functions.php, but now I cannot use for instance add_action("bp_nav_items","bp_add_my_activity_link"); to add it to the menu in functions.php

    Could you please help? or maybe this is outside this forum scope?

    again, thank you,

    bruno


    Bruno Henriques
    Participant

    or even simpler :

    <a href=”<?php echo bp_loggedin_user_domain() ?>profile/public”>My Activity</a>

    Andy
    Andy
    Keymaster

    Hi Bruno,

    The only way I can think of doing this is via jQuery. 

    This isn't tested but try adding a CSS class to the menu (Appearance -> Menus -> CSS Class) – you may need to enable CSS classes via Screen Options top right of Apperance Menus. Add something like activityurl

    Then edit DynamiX/footer.php 

    Search for 

    $(document).ready(function() {

    just below this line add the following

    $("li.activityurl a").attr("href", "<?php echo bp_loggedin_user_domain() ?>profile/public");


    Bruno Henriques
    Participant

    BINGO!

    perfect Andy, it works wonders, and I added the code (in footer.php) to check if the user is online, like:

    <?php if (  bp_is_active( 'activity' )&&  is_user_logged_in() ) : ?>

    $("li.activityurl a").attr("href", "<?php echo bp_loggedin_user_domain() ?>profile/public");

    <?php endif; ?>

    do you think it's further possible to "hide" this menu button while <?php if (  bp_is_active( 'activity' )&&  is_user_logged_in() ) : ?>  =  false ?

    thank you


    Bruno Henriques
    Participant

    … or maybe I just redirect the user (as on other pages) to the login page!!!! All is well then!

    thanks again

    Andy
    Andy
    Keymaster

    Hi Bruno,

    What about this

     <?php if (! bp_is_active( 'activity' )&&  !is_user_logged_in() ) : ?>

    $("li.activityurl a").attr("href", "<?php echo bp_loggedin_user_domain() ?>profile/public");

    <?php endif; ?>


    Bruno Henriques
    Participant

    eheh, no, buddypress refuses to "give" bp_loggedin_user_domain() if NOT bp_is_active or if the user is not logged in.

    what I will try to do next, is creating 2 different menus, one for loged in users and another one just containing some pages… I recall you telling some other member that this should be possible ( maybe in header.php ? )

    thanks again for all your help,

    bruno


    Bruno Henriques
    Participant

    sorry to be hijacker, but you call the menu by menu_id, here, right ?

    wp_nav_menu(array('echo' => true,'container' => 'ul','menu_id' => 'dyndropmenu','theme_location' => 'mainnav','walker' => $walker ));

    if so, I guess with the other code checking the user, I could give a new id to the call and hence a different menu…

    thanks,

    bruno

    Andy
    Andy
    Keymaster

    Yes that calls a custom menu – change the mainnav to another name and you'll also need to register a new menu within functions.php.

    Add one to this array (functions.php)

    'mainnav' => __( 'Main Navigation', 'NorthVantage' ),


    Bruno Henriques
    Participant

    yep, it's working perfectly!!!!

    I'm liking very much your "code" styling, very easy to follow, being that I first met wordpress the day I've decided to buy this template, I'm finding (the fun way) that your code is beautifully written!

    thanks again,

    bruno

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.