BuddyDev

Search

[Resolved] Custom Recent visitor code

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #31673

    Hi Brajesh, found this old code snippet, with which I can list Recent visitors anywhere. But where do I define, where I want to list it, should I use a hook, and how do I ad this to the code?

    /* custom Recent visitor code to list it anywhere for logged in user */
    $visitors = visitors_get_recent_visitors(get_current_user_id(), 5);//pass the user id for which we are retriving and how many we want
    foreach( (array) $visitors as $visitor_id ){
        echo bp_core_get_userlink( $visitor_id );//display the name of the 
        //bp_core_get_user_displayname( $visitor_id ); //use it to fetch the user display name
        //bp_core_get_user_domain( $visitor_id ); //use it to get user profile url
        //bp_core_fetch_avatar( array('item_id'=> $visitor_id, 'height'=>25, 'width'=> 25)); //fetch user avatar
    }

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24247
    Brajesh Singh on #31676

    Hi Carsten,

    Thank you for the question. You need to put it where you want to use it.

    In my opinion, you should try to use our shortcode instead of this code. They do the same thing.

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #31698

    Hi Brajesh, thanks for the suggestion, where do I find the mentioned shortcode, and how does this differs from your recent visitors plugin, except maybe from some more settings?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24247
    Brajesh Singh on #31712

    Hi Carsten,
    The shortcode is provided by the recent visitors plugin to make it easier list the visitors.

    Please see this section for details
    https://buddydev.com/plugins/recent-visitors-for-buddypress-profile/#shortcode-bp-visitors-recent-visitors

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #31738

    Hi Brajesh, I was not aware of the shortcodes, as they are not to be found in the settings.
    When you install a plugin, you expect to see all information within the settings of the plugin, not on the website, so maybe it is a good idea to ad it there as well.

    Here is the case, I want to show 10 recent visitors, of the logged in user, in the last 24 hours, but this code is not working, how should it look?

    [bp-visitors-recent-visitors max=10 duration=1]

    What happens when the 24 hours are exceeded, is the list reset to zero then?

    Regards
    Carsten

  • Keymaster
    (BuddyDev Team)
    Posts: 24247
    Brajesh Singh on #31744

    Hi Carsten,
    Thank you for telling me about the documentation expectation. I will be noting it and making sure to streamline in future.

    These plugins have grown with time and there have been a lot of change. There was no shortcode or widget or directory tab or even profile tab in the initial version. We need to keep updating the plugin docs with these changes. We will be adding link to our documentation in the plugin.

    Now about your question:-

    1. If you use the above code, It will list the most recent 10 visitors of the logged user. There is no concept of reset. If there are only 2 visitors in last 24 hours and you use the above code, It will list 2 users only.

    The list will be zero only if there are no recent visitors in last 24 hours.

    Hope it clarifies.

    Regards
    Brajesh

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #31748

    Hi Brajesh, thanks for clarifying.

    >The list will be zero only if there are no recent visitors in last 24 hours.

    So opposite using the Profile Tab, which shows only the accumulated visits total, within 7 days and a month, this shortcode displays new visits within eg. 24 hours. To me this counts as a daily reset.

    A similar option for setting the time interval for the Profile Tab as well, down to one day, would be nice to have, and an option for which time frame you want to display as default.

    Thanks

    Regards
    Carsten

  • Participant
    Level: Yogi
    Posts: 1105
    calu on #31750

    I’m trying to style the recent visitors shortcode avatars, but this class does not apply div.shortcode-recent-visitors

    Can you supply me with the right one to use?

    Thanks

    • This reply was modified 3 years, 9 months ago by calu.
  • Participant
    Level: Yogi
    Posts: 1105
    calu on #31774

    Problem solved, forgot to ad img

  • Keymaster
    (BuddyDev Team)
    Posts: 24247
    Brajesh Singh on #31781

    Hi Carsten,
    Thank you for the update. I am glad it is resolved.

    Regards
    Brajesh

The topic ‘ [Resolved] Custom Recent visitor code’ is closed to new replies.

This topic is: resolved