Skip to:
Content
Pages
Categories
Search
Top
Bottom

Counter of new feed publications


  • koka777
    Participant

    @koka777

    Hello, tell me if it is possible to receive the total number of new publications in the activity feed as a notification and place it, say, in the menu as the same counter of unread notifications?

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

  • chbing5828
    Participant

    @chbing5828

    Yes, it is possible to receive the total number of new publications in the activity feed as a notification and display it in the BuddyPress menu as a counter for unread notifications. Here’s a step-by-step approach to achieving this functionality within a BuddyPress-powered site:

    ### Step 1: Determine New Publications

    First, you’d need a method to tally the new publications since the user’s last visit. This can be done by recording the timestamp of the user’s last visit and comparing it with the timestamps of activity posts.

    ### Step 2: Create a Function to Count New Activities

    You can add a custom function in your theme’s functions.php file to count new activities:

    `php
    function bp_get_new_activity_count() {
    $last_visited = get_user_meta(get_current_user_id(), ‘last_visit’, true);
    $args = array(
    ‘action’ => ‘new_post’, // Adjust based on the actions you want to count
    ‘since’ => $last_visited, // Filter activities since the last visit
    );

    // Query BuddyPress activity with arguments
    $activities = new BP_Activity_Query($args);
    return $activities->get_total();
    }
    `

    ### Step 3: Update User Meta on Each Visit

    Each time a user logs in or visits the site, update the ‘last_visit’ meta to the current timestamp. This snippet goes in your theme’s functions.php file or a custom plugin:

    `php
    function bp_update_last_visit() {
    if (is_user_logged_in()) {
    update_user_meta(get_current_user_id(), ‘last_visit’, current_time(‘mysql’));
    }
    }
    add_action(‘wp_login’, ‘bp_update_last_visit’); // Update on login
    add_action(‘wp’, ‘bp_update_last_visit’); // Update on page load
    `

    ### Step 4: Display the Notification Counter

    Now that you have a function to get the count of new activities, you can invoke this function in your BuddyPress theme’s navigation menu where you want the counter to appear:

    `php
    function add_activity_notification_count() {
    $count = bp_get_new_activity_count();
    if ($count > 0) {
    echo ‘<span class=”activity-notification-count”>’ . $count . ‘</span>’;
    }
    }
    add_action(‘bp_menu’, ‘add_activity_notification_count’); // You may need to change the hook based on your theme.
    `

    ### Step 5: Style the Notification Counter

    Add some CSS in your theme’s stylesheet to style the notification counter:

    `css
    .activity-notification-count {
    background-color: red;
    color: white;
    padding: 2px 5px;
    border-radius: 50%;
    font-size: 12px;
    }
    `

    ### Step 6: Test The Implementation

    After adding this functionality, test it across various user scenarios to ensure it works correctly. Check if the counter updates appropriately appear in the right place, and reset when expected.

    By following these steps, you can effectively add a notification feature in BuddyPress that shows the count of new activity publications since the user’s last visit, enhancing the interactive experience of your site (beach buggy racing mod apk)


    koka777
    Participant

    @koka777

    Unfortunately it doesn’t work!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar