buddypress adding members online page

I am trying to add a page for "members online' in buddypress. ive added the widget for this on my footor pages but i cant find the shortcode to insert just a whos online page. thanks

  • Nahid

    Hey Murray !
    Hope you are having a great day!

    Well, BuddyPress doesn't offer a shortcode for just showing the online members in a page/post out of the box. For this, you need to set up a custom page template with the BuddyPress members loop.

    First of all create a new page template inside your theme/child theme. Here's a guide on how to create a custom page template. You can also create a shortcode if you want. Here's a guide on how to create a shortcode.

    However, lets move forward. Put the following members loop inside your custom page template or shortcode.

    <?php if ( bp_has_members( 'type=online' ) ) : ?>
    
      <div id="pag-top" class="pagination">
    
        <div class="pag-count" id="member-dir-count-top">
    
          <?php bp_members_pagination_count(); ?>
    
       </div>
    
       <div class="pagination-links" id="member-dir-pag-top">
    
          <?php bp_members_pagination_links(); ?>
    
       </div>
    
      </div>
    
      <?php do_action( 'bp_before_directory_members_list' ); ?>
    
      <ul id="members-list" class="item-list" role="main">
    
      <?php while ( bp_members() ) : bp_the_member(); ?>
    
        <li>
          <div class="item-avatar">
             <a href="<?php bp_member_permalink(); ?>"><?php bp_member_avatar(); ?></a>
          </div>
    
          <div class="item">
            <div class="item-title">
               <a href="<?php bp_member_permalink(); ?>"><?php bp_member_name(); ?></a>
    
               <?php if ( bp_get_member_latest_update() ) : ?>
    
                  <span class="update"> <?php bp_member_latest_update(); ?></span>
    
               <?php endif; ?>
    
           </div>
    
           <div class="item-meta"><span class="activity"><?php bp_member_last_active(); ?></span></div>
    
           <?php do_action( 'bp_directory_members_item' ); ?>
    
          <?php
           /***
            * If you want to show specific profile fields here you can,
            * but it'll add an extra query for each member in the loop
            * (only one regardless of the number of fields you show):
            *
            * bp_member_profile_data( 'field=the field name' );
           */
           ?>
           </div>
    
           <div class="action">
    
               <?php do_action( 'bp_directory_members_actions' ); ?>
    
          </div>
    
          <div class="clear"></div>
       </li>
    
     <?php endwhile; ?>
    
     </ul>
    
     <?php do_action( 'bp_after_directory_members_list' ); ?>
    
     <?php bp_member_hidden_fields(); ?>
    
     <div id="pag-bottom" class="pagination">
    
        <div class="pag-count" id="member-dir-count-bottom">
    
           <?php bp_members_pagination_count(); ?>
    
        </div>
    
        <div class="pagination-links" id="member-dir-pag-bottom">
    
          <?php bp_members_pagination_links(); ?>
    
        </div>
    
      </div>
    
    <?php else: ?>
    
       <div id="message" class="info">
          <p><?php _e( "Sorry, no members were found.", 'buddypress' ); ?></p>
       </div>
    
    <?php endif; ?>

    This code added to a custom page template or added as a shortcode will output your online members.

    Hope this helps. Let me know if you need any further assistance regarding this. Thanks!

    Best,
    Nahid.

  • Nahid

    Hey Murray !
    Hope you are doing great today!

    I have installed a child theme. There are a few folders within the child theme. Where should i post the template to in the child theme?

    The custom page template file should be inside your root theme directory, not inside any folders.

    Or if I create a shortcode and insert this on a page template will the format be the same as my themco x templates?

    Yes, well at least if your theme is using the default BuddyPress HTML layout, which it should by default.

    Let me know if you need any further assistance regarding this. Thanks!

    Best,
    Nahid.

  • Nahid

    Hey Murray !
    Hope you are doing well today!

    Well, if you have added the page template correctly, you should be able to select your page template inside the Page Attributes section while creating your new page. Here's a screenshot as an example. IF that doesn't show up, can you attach your members-custom-template.php in a zipped folder and attach it in your next reply?

    For the location, can you refer to this thread from the BuddyPress forums?

    Hope this helps. Thanks!

    Best,
    Nahid.

  • Nahid

    He Murray !
    Hope you are doing well today!

    You should place your file in the x-child directory and not inside any other folder. According to this guide, the template name in the page attributes should be the same as the Template Name you set in your files as comments. Here's a screenshot as a reference:

    Let me know what the results are. And when you upload the file, make sure you upload a copy of your page.php file from the parent theme too. It may be needed later for the header and footer.

    Thanks!

    Regards,
    Nahid.

  • Nahid

    Hey Murray !
    Hope you are doing well today!

    It'd be helpful if you could attach your custom-page.php file in your next reply. Moreover, can you please grant Staff Access on your site? To grant Staff Access, you can try following this handy guide.
    See https://premium.wpmudev.org/manuals/wpmu-dev-dashboard-enabling-staff-login/

    I'll be looking forward to hearing from you. Thanks!

    Best,
    Nahid.

  • Nahid

    Hey Murray!
    Hope you are having a great day and please excuse my late response!

    Well, it seems to be some problems with your PHP file. Unfortunately, I can't find the PHP file attached to your post for some reason. Can you try zipping the file and attach the zip folder here? If that doesn't work, you can upload the PHP file in a cloud storage service like Dropbox and post the link here.

    Moreover, can you send your FTP and other credentials through our secure contact form?

    https://premium.wpmudev.org/contact/#i-have-a-different-question

    Send in:

    Subject: "Attn: Nahid Mohit"
    -WordPress admin username
    -WordPress admin password
    -login url
    -FTP credentials (host/username/password)
    -link back to this thread for reference
    -any other relevant urls

    Thanks!

    Best,
    Nahid.