Viewing 15 replies - 1 through 15 (of 53 total)
  • I second this request. It would be very helpful and a lot of people with bbpress would benefit.

    Plugin Author Jonathan Daggerhart

    (@daggerhart)

    Hi,

    I’m a little caught up in work at the moment, but I’ve been thinking through this. I’ve read the thread you linked to, but could you clarify exactly what you’re looking for?

    As I understand it, you want a list of recent replies grouped by topic? If that’s the case, the grouping-by-topic would be difficult, and I’d have to add something for that to QW.

    If you just need a list of recent replies with links to the reply and to the topic, that’s no trouble at all.

    Thanks,
    Jonathan

    Thread Starter Ovidiu

    (@ovidiu)

    Ok so here goes:

    say there are ten threads. the last 5 people to comment, all commented on 1 thread. The recent replies widget should NOT show those 5 but the last comment of that thread and another 4 last comments to other threads and if clicked should link to those particular last comments not to the beginning of the thread.

    The recent threads widget should simply link to the latest 5 threads that have been created.

    At least that is what would make me happy. I don’t want to speak for other people but if you could create a sample of that and export I’m sure I and other could pick it up and play around with it.

    I personally was just a bit overwhelmed by all the options your plugin offers so I just need a good starting base and I’ll then play and modify whatever you give us as a starting point.

    Plugin Author Jonathan Daggerhart

    (@daggerhart)

    Ok, query wrangler doesn’t currently support the feature you need (group by). It’s on my radar, but I’m not sure when I’ll get a chance to add this in.

    If you’d like, I can write a snippet/shortcode that would produce the results you’re looking for. You could paste that snippet in your theme’s function.php file, and share it with the others at bbpress who are looking for this feature.

    Thread Starter Ovidiu

    (@ovidiu)

    Sure, if you have the time, I’d like to give that a try.

    Plugin Author Jonathan Daggerhart

    (@daggerhart)

    Ok, this is a little complex because I was trying to use only WP_Query args for the query as an exercise, but it should work.

    Also, I’m not sure how well this will display, so it may take me a few edits.

    add_shortcode('bbpress_recent_replies_by_topic', 'custom_bbpress_recent_replies_by_topic');
    /*
     * Get the most recently replied to topics, and thier most recent reply
     */
    function custom_bbpress_recent_replies_by_topic($atts){
      $short_array = shortcode_atts(array('show' => 5), $atts);
      extract($short_array);
    
      // get the 5 topics with the most recent replie
      $args = array(
        'posts_per_page' => $show,
        'post_type' => array('topic'),
        'orderby' => 'meta_value',
        'order' => 'DESC',
        'meta_key' => '_bbp_last_reply_id',
      );
    
      $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(), '_bbp_last_reply_id', true)){
          $reply_ids[] = $reply_post_id;
        }
      }
    
      // get the actual replies themselves
      $args = array(
        'posts_per_page' => $show,
        'post_type' => array('reply'),
        '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();
        }
      $output = ob_get_clean();
      return $output;
    }
    
    /*
     * Executed during our custom loop
     *  - this should be the only thing you need to edit
     */
    function custom_bbpress_recent_reply_row_template(){
      ?>
        <div class="bbpress-recent-reply-row">
          <div><?php the_title(); ?></div>
          <div>Excerpt: <?php the_excerpt(); ?></div>
          <div>Author: <?php the_author(); ?></div>
          <div>Link: <a>">view reply</a></div>
        </div>
      <?php
    }

    Here is a little walk through.

    I’ve added a custom shortcode. You use the this shortcode like so: [bbpress_recent_replies_by_topic]. It also allows for a parameter to determine the number of replies shown (defaults to 5). That parameter is “show”, and is used in the shortcode like so: [bbpress_recent_replies_by_topic show=10]

    That shortcode calls the first function. This function gathers the 5 most recent replied-to topics, and their most recent replies. Then while looping through the replies, it calls the 2nd function to output a row of data.

    I broke it into 2 functions so that you could easily edit the output of a row without breaking anything else. This means, to change the way the rows look you should [b]only edit the “custom_bbpress_recent_reply_row_template()” function[/b].

    I don’t expect that this is as user-friendly as everyone might hope, but it should get you in the right direction. If you’re used to editing themes, then nothing about the custom_bbpress_recent_reply_row_template() function should surprise you.

    Hope this helps. Let me know how it turns out.

    edit: trying to make the code look right.

    Plugin Author Jonathan Daggerhart

    (@daggerhart)

    And… just for fun, here is a version of the same thing that uses a sql query to get the list of replies instead of having 2 loops.

    There shouldn’t be any difference in the results. Just doing the same thing a slightly different way.

    /*
     * Get the most recently replied to topics, and thier most recent reply
     */
    function custom_bbpress_recent_replies_by_topic($atts){
      $short_array = shortcode_atts(array('show' => 5), $atts);
      extract($short_array);
    
      global $wpdb;
      $reply_ids = $wpdb->get_col($wpdb->prepare("SELECT pm.meta_value FROM {$wpdb->postmeta} as pm LEFT JOIN {$wpdb->posts} as p on pm.post_id = p.ID where p.post_type = 'topic' AND pm.meta_key = '_bbp_last_reply_id' order by pm.meta_value DESC LIMIT %d", $show));
    
      // get the actual replies themselves
      $args = array(
        'posts_per_page' => $show,
        'post_type' => array('reply'),
        '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();
        }
      $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
     */
    function custom_bbpress_recent_reply_row_template(){
      ?>
        <div class="bbpress-recent-reply-row">
          <div><?php the_title(); ?></div>
          <div>Excerpt: <?php the_excerpt(); ?></div>
          <div>Author: <?php the_author(); ?></div>
          <div>Link: <a href="<?php the_permalink(); ?>">view reply</a></div>
        </div>
      <?php
    }

    edit: slight adjustment for initial query limit

    Thread Starter Ovidiu

    (@ovidiu)

    I’ve modified the output a bit and added two lines below to allow usage of shortcodes in widgets but the output heavily differs from what I expected. i.e. all threads listed by your code are very old, slightly confused now :-/

    add_shortcode('bbpress_recent_replies_by_topic', 'custom_bbpress_recent_replies_by_topic');
    /*
     * Get the most recently replied to topics, and thier most recent reply
     */
    function custom_bbpress_recent_replies_by_topic($atts){
      $short_array = shortcode_atts(array('show' => 5), $atts);
      extract($short_array);
    
      // get the 5 topics with the most recent replie
      $args = array(
        'posts_per_page' => $show,
        'post_type' => array('topic'),
        'orderby' => 'meta_value',
        'order' => 'DESC',
        'meta_key' => '_bbp_last_reply_id',
      );
    
      $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(), '_bbp_last_reply_id', true)){
          $reply_ids[] = $reply_post_id;
        }
      }
    
      // get the actual replies themselves
      $args = array(
        'posts_per_page' => $show,
        'post_type' => array('reply'),
        '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();
        }
      $output = ob_get_clean();
      return $output;
    }
    
    /*
     * Executed during our custom loop
     *  - this should be the only thing you need to edit
     */
    function custom_bbpress_recent_reply_row_template(){
      ?>
        <div class="bbpress-recent-reply-row">
          <ul>
    	 <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
         <li>by: <?php the_author(); ?></li>
    	  </ul>
        </div>
      <?php
    }	  
    
    add_filter( 'widget_text', 'shortcode_unautop');
    add_filter( 'widget_text', 'do_shortcode');

    You can check it live here: http://www.die-kellerkinder.eu/

    The TOP Recent Replies is what I was using before I asked here and missing a few of the features I mentioned to you.

    Towards the bottom, YOUR code outputs to where it says: Recent Replies TEST.

    Cayn you double check the results and then your code maybe?

    Plugin Author Jonathan Daggerhart

    (@daggerhart)

    Try this. https://gist.github.com/daggerhart/09b0dbc7eb766486353b

    I added a bit more specificity to the query regarding post_status and orderby. You probably don’t want the row output function, just the queries.

    If you have problems with this version as well, let me know.

    Thread Starter Ovidiu

    (@ovidiu)

    THX!

    Almost there. Is it possible to jump/link here: http://www.die-kellerkinder.eu/forums/topic/dfb-pokalfinale-und-grillen/#post-7365
    instead of here: http://www.die-kellerkinder.eu/forums/reply/7365/ ?

    That would be the most important part…

    The less relevant parts would be i.e. I changed my output to this:

    <div class="bbpress-recent-reply-row">
    	<ul>
          <li><a href="<?php the_permalink(); ?>"><?php print str_replace('Reply To: ', '', get_the_title()); ?></a></li>
    	  <li>by: <?php the_author(); ?></li>
    	</ul>
    	</div>

    a) any chance to get user avatar function in here?
    b) possible to show reply date or time-since?

    Plugin Author Jonathan Daggerhart

    (@daggerhart)

    I’ve updated the gist: https://gist.github.com/daggerhart/09b0dbc7eb766486353b . Now includes code for avatar, linking to topic with post id fragment, post date, and time ago.

    You should be able to use that code within your row template function as needed.

    Thread Starter Ovidiu

    (@ovidiu)

    You’ve done it! Awesome! (I’m almost there! – being a bit pedantic here 😉

    Read the reference links you gave and managed to change and reformat my avatar size too. Check it out live where the widget title says: “Recent Replies TEST”: http://www.die-kellerkinder.eu/

    Not important but I’m looking into this:

    • how to get the link to the author’s “member” page (Buddypress) I figured out how to link to the WordPress author page though! <?php the_author_posts_link(); ?>
    • how to cut i.e. the topic title at a specific length to keep all the titles the same length

    Here is my output format if anyone’s interested:

    function custom_bbpress_recent_reply_row_template(){
      ?>
        <div class="bbpress-recent-reply-row">
    	<ul>
       	  <li><a href="<?php print get_permalink( get_post_meta( get_the_ID(), '_bbp_topic_id', true) ); ?>#post-<?php the_ID(); ?>"><?php print str_replace('Reply To: ', '', get_the_title()); ?></a></li>
    	  <li>by: <?php print get_avatar( get_the_author_meta( 'ID' ),'14' ); ?> <?php the_author(); ?> <?php print human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></li>
    	  </ul>
    	</div>
      <?php
    }
    Thread Starter Ovidiu

    (@ovidiu)

    Jonathan, can I somehow pay you a beer or two? Do you have a site with a Paypal button or some such? This feature has been requested since bbpress was updated to version 2 and nobody gave a f**k :-/

    Plugin Author Jonathan Daggerhart

    (@daggerhart)

    I’ve updated the gist to show trimming the title in 2 different ways, as well as getting the bbpress profile link. https://gist.github.com/daggerhart/09b0dbc7eb766486353b

    I changed the title around so that each function we’re running on it could be removed if desired. You will probably want to adjust your code to be like:

    function custom_bbpress_recent_reply_row_template(){
      // get the reply title
      $title = get_the_title();
      // 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);
      ?>
        <div class="bbpress-recent-reply-row">
    	<ul>
       	  <li><a href="<?php print get_permalink( get_post_meta( get_the_ID(), '_bbp_topic_id', true) ); ?>#post-<?php the_ID(); ?>"><?php print $title; ?></a></li>
    	  <li>by: <a href="<?php print esc_url( bbp_get_user_profile_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php print get_avatar( get_the_author_meta( 'ID' ),'14' ); ?></a> <?php print bbp_user_profile_link( get_the_author_meta( 'ID' ) ); ?> <?php print human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></li>
    	  </ul>
    	</div>
      <?php
    }

    In the above code I’ve linked the avatar to the user’s profile to be more like the other widget on your page.

    Yes, I have a donate link on widget wrangler’s homepage http://widgetwrangler.com/ It’s on the top right. Thanks, and no problem!

    Thread Starter Ovidiu

    (@ovidiu)

    Donated for 2 beers or coffees (I hope) 🙂

    Sorry to keep asking for more but can you point me towards how to change the widget output structure?

    Currently this code:

    <div class="bbpress-recent-reply-row">
    	<ul>
       	  <li><a href="<?php print get_permalink( get_post_meta( get_the_ID(), '_bbp_topic_id', true) ); ?>#post-<?php the_ID(); ?>"><?php print $title; ?></a></li>
    	  <li>by: <a href="<?php print esc_url( bbp_get_user_profile_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php print get_avatar( get_the_author_meta( 'ID' ),'14' ); ?></a> <?php print bbp_user_profile_link( get_the_author_meta( 'ID' ) ); ?> <?php print human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?></li>
    	  </ul>
    	</div>

    wraps each of those 5 entries “entry” in div ul li tags but what I was trying to achieve was that ALL 5 entries are inside an ul and each entry is inside a li tag. All of that inside a div (for the complete widget).

    So I replaced the above code with

    <li class="bbpress-recent-reply-row">
    				 <a href="<?php print get_permalink( get_post_meta( get_the_ID(), '_bbp_topic_id', true) ); ?>#post-<?php the_ID(); ?>"><?php print $title; ?></a><br />
    	  by: <a href="<?php print esc_url( bbp_get_user_profile_url( get_the_author_meta( 'ID' ) ) ); ?>"><?php print get_avatar( get_the_author_meta( 'ID' ),'14' ); ?></a> <?php print bbp_user_profile_link( get_the_author_meta( 'ID' ) ); ?> <?php print human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' ago'; ?>
    	</li>

    But that is missing the ul tag around all of these 5 li tags and I’m not sure where to add that…

    Additionally I was trying to set alternating css classes so I can style each li tag alternating but it doesn’t seem to work.

    I tried adding this code:

    example-class<?php echo ($xyz++%2); ?>

    but it always outputs example-class0 and doesn’t alternate. Any suggestions?

Viewing 15 replies - 1 through 15 (of 53 total)
  • The topic ‘Need some help getting this right?’ is closed to new replies.