Skip to:
Content
Pages
Categories
Search
Top
Bottom

Last reply author’s name in loop-single-topic?


  • kasperdalkarl
    Participant

    @kasperdalkarl

    Hi!

    I was wondering if it’s possible to add the latest reply author’s in loop-single-topic. I am configuring my forum a bit on my site talanrien.com/rollspel

    Currently it’s like this:

    Topic Name
    Reply To: Topic name
    Started by Topic auhtor in: Name of subforum

    What I would like is:

    Topic Name
    REPLY AUTHOR’S NAME, Reply To: Topic name
    Started by Topic auhtor in: Name of subforum

    Does anyone have any suggestions on how to add the latest reply author’s name in the place I want?

    Thanks!

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

  • Robin W
    Moderator

    @robin-w

    so have you added Reply To: Topic name to the template ?


    kasperdalkarl
    Participant

    @kasperdalkarl

    It probably comes from the theme I have, it currently looks like this in loop-single-topic:

       <div class="nk-forum-title-sub">
    
          
            <?php
            $link_url = bbp_get_topic_last_reply_url();
            $title = bbp_get_topic_last_reply_title();
            ?>
            <div class="nk-forum-activity-title" title="<?php echo esc_attr($title); ?>">
                <a href="<?php echo esc_url($link_url); ?>"><?php echo esc_html($title); ?></a>
            </div>
            
            
             <div class="nk-forum-activity-date">
                <?php do_action('bbp_theme_before_topic_freshness_link'); ?>
                <?php $time_since = bbp_get_topic_last_active_time();
                if (!empty($time_since)) {
                    echo esc_html($time_since);
                } else {
                    echo esc_html__('No Replies', 'godlike');
                }
                ?>
                <?php do_action('bbp_theme_after_topic_freshness_link'); ?>
            </div>
               
    
                <?php do_action('bbp_theme_before_topic_started_by'); ?>
    
                <span
                    class="bbp-topic-started-by"><?php printf(esc_html__('Started by %1$s', 'godlike'), bbp_get_topic_author_link(array('type' => 'name')), bbp_get_reply_post_date()); ?></span>
    
                <?php do_action('bbp_theme_after_topic_started_by'); ?>
    
                <?php if (!bbp_is_single_forum() || (bbp_get_topic_forum_id() !== bbp_get_forum_id())) : ?>
    
                    <?php do_action('bbp_theme_before_topic_started_in'); ?>
    
                    <span
                        class="bbp-topic-started-in"><?php printf(__('in: <a href="%1$s">%2$s</a>', 'godlike'), bbp_get_forum_permalink(bbp_get_topic_forum_id()), bbp_get_forum_title(bbp_get_topic_forum_id())); ?></span>
    
                    <?php do_action('bbp_theme_after_topic_started_in'); ?>
    
                <?php endif; ?>
    
            </div>

    Robin W
    Moderator

    @robin-w

    ok, painting bedroom windows so I’ll come back later with a response 🙂


    kasperdalkarl
    Participant

    @kasperdalkarl

    Thanks a lot, it’s much appreciated!


    Robin W
    Moderator

    @robin-w

    ok, they’ve done it by a function by the look of it.

    so try this

    add_action ('bbp_theme_before_topic_started_by' , 'rew_reply_author' , 10 ) ;
    
    function rew_reply_author () {
    	$reply_id = bbp_get_topic_last_reply_id () ;
    	echo '<span class="bbp-reply-author">'.bbp_get_reply_author_link( array( 'post_id' => $reply_id, 'type' => 'both', 'size' => 14 ) ) ;
    }

    Put this in your child theme’s function file – or use

    Code Snippets

    then come back and let me know where this appears, we might need to adjust


    kasperdalkarl
    Participant

    @kasperdalkarl

    Hi there!
    Thanks for the help! I added it using Code Snippets, and now the last reply author’s name appears in front of “Started by”, as you can see on this link here: https://www.talanrien.com/rollspel/

    Maybe with some minor adjustment it could appear in front of “Reply To”. Thanks for your amazing help!


    Robin W
    Moderator

    @robin-w

    ok, hopefully that’s just a refinement of order

    try changing

    add_action ('bbp_theme_before_topic_started_by' , 'rew_reply_author' , 10 ) ;

    to

    add_action ('bbp_theme_before_topic_started_by' , 'rew_reply_author' , 5 ) ;

    or

    add_action ('bbp_theme_before_topic_started_by' , 'rew_reply_author' , 15 ) ;


    kasperdalkarl
    Participant

    @kasperdalkarl

    Hi again!
    I tried the different order numbers but no change sadly.


    Robin W
    Moderator

    @robin-w

    ok, so either it is a different version of that template or the function is firing from another hook.

    since you seem to have access to the files, can I suggest you search for ‘Reply To: ‘ exactly as it appears on your site, and see if you can find where it is in the theme. The template or file will get us there I hope


    kasperdalkarl
    Participant

    @kasperdalkarl

    Hey!

    Yeah I have actually been trying to do that for the last hour or so, but can’t find it anywhere. Any suggestions are appreciated, but my search continues in the files!


    kasperdalkarl
    Participant

    @kasperdalkarl

    Hi again!

    I managed to find it now. It’s here:
    wp-content/themes/godlike/bbpress/form-reply.php

    <?php if (bbp_is_reply_edit()) : ?>
    
    <div id="bbpress-forums">
    
        <?php endif; ?>
    
        <?php if (bbp_current_user_can_access_create_reply_form()) : ?>
            <div class="nk-gap-2"></div>
            <h3 class="h4"><?php printf(esc_html__('Reply To: %s', 'godlike'), bbp_get_topic_title()); ?></h3>
            <div class="nk-gap-1"></div>
            <div id="new-reply-<?php bbp_topic_id(); ?>" class="bbp-reply-form nk-box-3 bg-dark-1">
    
                <form id="new-post" name="new-post" method="post" class="nk-form" action="<?php the_permalink(); ?>">
    
                    <?php do_action('bbp_theme_before_reply_form'); ?>
    
                    <fieldset class="bbp-form">
    
                        <?php do_action('bbp_theme_before_reply_form_notices'); ?>
    
                        <?php if (!bbp_is_topic_open() && !bbp_is_reply_edit()) : ?>
    
                            <?php echo do_shortcode('[nk_info_box icon="fa fa-exclamation-circle" show_close_button="true" class="bg-main-1"]' . esc_html__('This topic is marked as closed to new replies, however your posting capabilities still allow you to do so.', 'godlike') . '[/nk_info_box]'); ?>
    
                        <?php endif; ?>

    Robin W
    Moderator

    @robin-w

    ok so change

    <div class="nk-gap-2"></div>

    to

    <div class="nk-gap-2"></div>
    		<?php
    		$reply_id = bbp_get_topic_last_reply_id () ;
    		echo '<span class="bbp-reply-author">'.bbp_get_reply_author_link( array( 'post_id' => $reply_id, 'type' => 'both', 'size' => 14 ) ) ;
    		?>

    kasperdalkarl
    Participant

    @kasperdalkarl

    Thanks again for your amazing help!

    I did as you asked, and I realized a few things.

    Adding your code in form-reply.php only changed how it looks in the reply form, i.e. when you open a thread and scroll down to the actual box where you write replies.

    What I realised is that “Reply To:” that shows in the forums is actually not from code, it’s automatically added to the topic name when someone answers a thread.
    Reply to

    So the follow up question is, can you somehow in bbpress change so replies doesn’t add “Reply To”, I would like to change it to the Swedish equivalent: “Svar till:”. And is it possible then to add what we tried earlier with the avatar+name in front of the name of the topic reply?

    Thanks a lot!


    Robin W
    Moderator

    @robin-w

    is bbpress not translated in Swedish ?


    kasperdalkarl
    Participant

    @kasperdalkarl

    Yeah but for my needs I don’t really need to translate the whole site. But if that’s the best way I will of course give it a shot! Thanks a lot for your help! You have been the most helpful mod I’ve ever met online and your solution works really great for what I needed!


    Robin W
    Moderator

    @robin-w

    ok, understand

    if you just want that then

    add_filter(  'gettext',  'rew_bbpress_translate', 20 , 3  );
    
    function rew_bbpress_translate( $translated, $text, $domain ) {
    	if ($domain == 'bbpress') {
         $words = array(
                            
                            'Reply To:' => 'Svar till:',
    			            );
         $translated = str_replace(  array_keys($words),  $words,  $translated );
    	}
         return $translated;
    }

    Put this in your child theme’s function file – or use

    Code Snippets


    kasperdalkarl
    Participant

    @kasperdalkarl

    Thanks, that worked perfectly. Now I got my forum set up just as my users want it. Thanks a lot for your amazing and fast assistance!


    Robin W
    Moderator

    @robin-w

    great – glad you are fixed

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