• Resolved mglasser

    (@mglasser)


    Is it possible to have a widget that shows recent “actvity”? This would include new topics that are created and replies to existing topics, in one widget.

    While researching this question as I write this, I came across the option in your Recent Topics widget to show “Topics with Recent Replies”. Is this the functional equivalent of combining the two widgets?

    Topic A created January
    Topic B created March
    Topic C created June
    Topic A has a reply made April

    If I were to show most recent 3, I would expect to see

    Topic C
    Topic A
    Topic B

    https://www.ads-software.com/plugins/bbp-private-groups/

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author Robin W

    (@robin-w)

    I think a widget that would do this would be a great idea !

    But at the moment I am fairly tied up in paid website development, and in my free website time I’m writing a styling plugin for bbpress.

    The widget would fit nicely into this plugin, but I need to complete version 1 before adding such functionality, but would allow my private groups plugin to hook to it.

    So it will be a while before this exists for free !

    elucidateTX

    (@elucidatetx)

    Hey all. I know this is a resolved topic, but I was able to snag code from this other topic to do this at a general (non-private groups) level.

    Here’s their code (with a few simplifying edits from me):

    /*
    * Get the most recently replied-to topics, and their most recent reply
    */
    function custom_bbpress_recent_replies_by_topic($atts){
    $short_array = shortcode_atts(array('show' => 5, 'forum' => false, 'include_empty_topics' => false), $atts);
    extract($short_array);
    // default values
    $post_types = array('reply');
    $meta_key = '_bbp_last_reply_id';
    // allow for topics with no replies
    if ($include_empty_topics) {
    $meta_key = '_bbp_last_active_id';
    $post_types[] = 'topic';
    }
    // get the 5 topics with the most recent replies
    $args = array(
    'posts_per_page' => $show,
    'post_type' => array('topic'),
    'post_status' => array('publish'),
    'orderby' => 'meta_value_num',
    'order' => 'DESC',
    'meta_key' => $meta_key,
    );
    // allow for specific forum limit
    if ($forum){
    $args['post_parent'] = $forum;
    }
    $query = new WP_Query($args);
    $reply_ids = array();
    // get the reply post->IDs for these most-recently-replied-to-topics
    while($query->have_posts()){
    $query->the_post();
    if ($reply_post_id = get_post_meta(get_the_ID(), $meta_key, true)){
    $reply_ids[] = $reply_post_id;
    }
    }
    // get the actual replies themselves
    $args = array(
    'posts_per_page' => $show,
    'post_type' => $post_types,
    'post__in' => $reply_ids,
    'orderby' => 'date',
    'order' => 'DESC'
    );
    $query = new WP_Query($args);
    ob_start();
    // loop through results and output our rows
    while($query->have_posts()){
    $query->the_post();
    // custom function for a single reply row
    custom_bbpress_recent_reply_row_template( $query->current_post + 1 );
    }
    $output = ob_get_clean();
    return $output;
    }
    add_shortcode('bbpress_recent_replies_by_topic', 'custom_bbpress_recent_replies_by_topic');
    /*
    * Executed during our custom loop
    * - this should be the only thing you need to edit
    */
    /*
    * Executed during our custom loop
    * - this should be the only thing you need to edit
    */
    function custom_bbpress_recent_reply_row_template( $row_number ){
    // get the reply title
    $title = get_the_title();
    // optional title adjustments -- delete or comment out to remove
    // remove "Reply To: " from beginning of title
    /* $title = str_replace('Reply To: ', '', $title); */
    // trim title to specific number of characters (55 characters)
    $title = substr( $title, 0, 55);
    // trim title to specific number of words (5 words)...
    /* $title = wp_trim_words( $title, 5, '...'); */
    // determine if odd of even row
    $row_class = ($row_number % 2) ? 'odd' : 'even';
    ?>
    <div class="bbpress-recent-reply-row <?php print $row_class; ?>">
    	<div><a href="<?php print get_permalink( get_post_meta( get_the_ID(), '_bbp_topic_id', true) ); ?>#post-<?php the_ID(); ?>"><?php print $title; ?></a>
    	<div>By: <?php the_author(); ?></div>
    	<div><?php print human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></div>
    	<div><br></div>
    </div>
    <?php
    // Refs
    // https://codex.www.ads-software.com/Template_Tags#Post_tags
    // https://codex.www.ads-software.com/Function_Reference/get_avatar
    // https://codex.www.ads-software.com/Function_Reference/human_time_diff
    // (template tags for bbpress)
    // https://bbpress.trac.www.ads-software.com/browser/trunk/src/includes/users/template.php
    // https://bbpress.trac.www.ads-software.com/browser/trunk/src/includes/replies/template.php
    }
    // allow shortcodes to run in widgets
    add_filter( 'widget_text', 'do_shortcode');
    // don't auto-wrap shortcode that appears on a line of it's own
    add_filter( 'widget_text', 'shortcode_unautop');

    To use it in a widget, you:
    1. Cut and paste the code into your child theme’s function.php file
    1. Create a new text widget
    2. Paste in the shortcode [bbpress_recent_replies_by_topic include_empty_topics=1]

    elucidateTX

    (@elucidatetx)

    While the code above provides a widget that merges the recent posts and replies activity…it doesn’t pull in the functionality of this excellent plugin of hiding these if people aren’t in the right group to be able to see them. Everyone can see all the activity.

    I’m just hoping this code might help Robin if she decides to incorporate a new widget into this plugin. I’d love to see it added too.

    Plugin Author Robin W

    (@robin-w)

    I created a widget that does latest activity in my style plugin

    https://www.ads-software.com/plugins/bbp-style-pack/

    Load this plugin and see if it is doing what you want for general forums.

    If you like it then I’ll create a version for private groups

    If you don’t like it, suggest what needs changing, before I code the wrong solution !!

    elucidateTX

    (@elucidatetx)

    Your widget is excellent Robin! I just didn’t see it. It does exactly what the code I posted does.

    I might make two small formatting suggestions if I can be so bold:
    1. Provide an option to hide the Gravatar
    2. Provide an option to shorten the date format

    Other than that, it’s perfect!

    Plugin Author Robin W

    (@robin-w)

    ok, but at the moment it doesn’t have a private groups version, so I’ll make one in the next few days, and add your suggestions

    Plugin Author Robin W

    (@robin-w)

    on your 2. above

    what does it show by default? My test site is so loaded with extra functions that play with dates I can’t remember what it is in the raw !

    and what would it be good to shorten it to?

    Plugin Author Robin W

    (@robin-w)

    ok, new version will be released tomorrow – hopefully !

    Plugin Author Robin W

    (@robin-w)

    Version 2.5.5 contains that latest activity widget !!

    Sorry just catching up on this. I saw that you added the widget. I love it! It went right up on my site.

    In answer to your question above on my #2 in my previous post, my freshness was typically saying “XX hours, YY minutes ago.” But in your new widget…whether or not I have the “Shorten freshness” box checked, it’s just showing XX days or YY hours or ZZ minutes. So, it doesn’t seem like that checkbox is toggling that truncating on and off…it’s just always truncated.

    That said, used in conjunction with your bbp last post plugin, it shows the date just as I think you intend…MM/DD/YYYY at ZZ:ZZPM

    Plugin Author Robin W

    (@robin-w)

    ah thanks, probably because I tested with my last post plugin active – I’ll take another look!

    Plugin Author Robin W

    (@robin-w)

    hmm, just tested on my site, and it is toggling the freshness fine.

    with Lasst post, it doesn’t work, you always get the longer, I could code that I s’pose, but can you come back after a further test on the freshness if you need that, or are you fixed with the last post date?

    The last post format is fine here. I just wanted you to know that was happening.

    Plugin Author Robin W

    (@robin-w)

    Great, and yes thanks for letting me know, all feedback is appreciated !

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Recent Activity widget’ is closed to new replies.