Skip to:
Content
Pages
Categories
Search
Top
Bottom

Recent Topics Widget – Changing Topic Author to Reply Author

  • @seeingblues2

    Participant

    I’m using the Recent Topics Widget with Order by set to Recent Replies. It’s working great except I would like to change the topic author that it displays to the latest reply author instead. Can someone tell me how to make this happen?

Viewing 14 replies - 1 through 14 (of 14 total)
  • @seeingblues2

    Participant

    Any suggestions? I imagine it would be a query change somewhere, shouldn’t be very difficult.

    @robin-w

    Moderator

    no it’s not difficult, but would take a bit of coding

    You’ll need to either create a copy function and use that or amend the topics widget and risk it being overwritten by updates.

    There’s no simple, filter I can see.

    so go into

    bbpress/includes/common/widgets.php

    and on line 807 you’ll see the author-link being created

    the correct solution would be to create a fresh version of this widget, by say copying it to your functions file and renaming it.

    If you just edit the core file, it will be overwritten by updates, but as long as you note what you’ve changed and accept that risk !…

    so you’d need to look up the last reply for that topic, and then do another author link for that reply.

    Sorry, I really busy at the moment earing a living or I so the coding .. so unless someone else steps in, see how far you can get 🙂

    @seeingblues2

    Participant

    Ok so I played around with lines 807 and made it match what line 1157 looked like.
    This is line 1157:$author_link = bbp_get_reply_author_link( array( 'post_id' => $reply_id, 'type' => 'both', 'size' => 14 ) );
    Then I moved line 1152$reply_id = bbp_get_reply_id( $widget_query->post->ID ); between lines 802 & 803 thinking this might work and it doesn’t make any difference which was confusing to me.. What am I doing wrong?

    @robin-w

    Moderator

    you’ll need to have some logic in here

    eg

    if there are replies find latest reply, and then find that replies author and insert that.
    if there are no replies, then put in topic author

    At the moment you looking up the reply author for a topic, and that won’t work.

    just had a play and this seems to work, but only tested quickly, so you’d need to set up a few topics with and without single and multiple replies and check that it worksin all circumstances

    // Maybe get the topic author
    if ( ! empty( $settings['show_user'] ) ) {
    //see if there has been replies, and if so set to latest
    $replycheck = get_post_meta( $topic_id, '_bbp_last_reply_id',true);
    //if we have replies ie replycheck holds the latest reply number
    if (!empty ($replycheck)) 
    $author_link = bbp_get_reply_author_link( array( 'post_id' => $replycheck, 'type' => 'both', 'size' => 14 ) );
    else
    $author_link = bbp_get_topic_author_link( array( 'post_id' => $topic_id, 'type' => 'both', 'size' => 14 ) );
    				} ?>
    
    

    @van24

    Participant

    Hi Robin

    I’m trying to get the same functionality that SeeingBlue is looking for. I copied the entire Recent Topics widget code into my functions.php, and I added your code in the correct place, but the widget is still behaving exactly the same.. Any idea what else I need to do?

    Thanks
    Van

    @robin-w

    Moderator

    I copied the entire Recent Topics widget code into my functions.php

    You need to copy and rename it.

    Then you use this new named widget, not the old one, so need to cal the new name in your sidebar.

    @van24

    Participant

    Hi Robin. Thanks for the tip. I changed all instances of BBP_Topics_Widget to BBP_Topics_Widget2. And I amended this line as well:
    parent::__construct( false, __( ‘(bbPress) Recent Topics 2’, ‘bbpress’ ), $widget_ops );

    But still I don’t see the new widget appearing in the WP Widget area.. Any idea what I’m doing wrong?

    @robin-w

    Moderator

    You’ll need to register it for it to go live, try the following in your functions file

    add_action( 'widgets_init', function(){
         register_widget( 'BBP_Topics_Widget2');
    });
    

    @van24

    Participant

    That worked perfectly! And the code you mentioned earlier in the thread is perfect. Thanks for your help 🙂

    @robin-w

    Moderator

    no problem – glad you’re fixed !

    @van24

    Participant

    Sorry one more question – would it be possible to remove the avatar from this widget? I know I can use display:none in the CSS, but I’d prefer not to make all the unnecessary requests to gravatar.com if possible.

    @robin-w

    Moderator

    wherever it says (think it’s more than once)

    'type' => 'both', 'size' => 14 ) );
    

    change to

    'type' => 'name', 'size' => 14 ) );
    

    @van24

    Participant

    Thanks Robin!

    @robin-w

    Moderator

    You’re welcome !

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