BBpress - Topic Excerpts

Hello,
I am wondering if it's possible to pull a small excerpt from the latest post in the forums vs have the "freshness information"?

I included some screenshots of what I'm talking about.

  • Nithin

    Hey Joshua,

    Hope you are doing good today. :slight_smile:

    If I'm not mistaken, I suppose you want to add the excerpts along with the topic title, if yes, please add the following in your themes functions.php, and then see whether it works fine:

    function add_topic_excerpt() {
    	echo "<p>".bbp_get_topic_excerpt()."</p>";
    }
    add_action('bbp_theme_after_topic_title', 'add_topic_excerpt' );

    You can add your HTML tags in the above, and style it accordingly. I hope this helps. Please let us know if you still need any further assistance. Have a nice day. :slight_smile:

    Best Regards,
    Nithin

  • Nithin

    Hey Randy,

    Hope you are doing good today. :slight_smile:

    Is there any way to specify the length of the topic excerpt? Currently, it seems to default to about 96 characters.

    Could you please replace the above code with the following one, and see whether that helps:

    function add_topic_excerpt() {
    	echo "<p>".bbp_get_topic_excerpt( $topic_id, 200)."</p>";
    }
    add_action('bbp_theme_after_topic_title', 'add_topic_excerpt' );

    In the given code, we specify the length of the character to be 200. You can increase/decrease the value according to your needs.

    I hope this helps. Please let us know if you still need any further assistance. Have a nice weekend. :slight_smile:

    Best Regards,
    Nithin

  • Joshua

    Hi Nithin ,

    That code works perfectly to add an excerpt after a topic title.

    What I'm looking for is to add the most recent topic under the "Freshness" column in the forum-loop.

    In the picture I posted you can see it. In the first picture (the one with the red color) , to the far right you can see it shows the "reply-to: topic by user". I was wondering how I can get my bbpress to show this.

    I managed to get what I wanted in sort of a "make shift" sort of way.

    What I did was I added a "bbpress" folder to my child theme and then added the "loop-single-forum.php" file to it.

    I think made some edits:

    I replaced this code:

    <?php do_action( 'bbp_theme_before_forum_freshness_link' ); ?>
    <?php bbp_forum_freshness_link(); ?>
    <?php do_action( 'bbp_theme_after_forum_freshness_link' ); ?>

    with this code:

    <a class="bbp-forum-freshness" href="<?php bbp_forum_last_reply_url(); ?>"><?php bbp_forum_last_topic_title(); ?></a>
    (<?php bbp_forum_last_active_time(); ?>)<span class="bbp-topic-freshness-author">by <?php bbp_author_link( array( 'post_id' => bbp_get_forum_last_active_id(), 'size' => 14 ) ); ?></span>

    So the result is I now have a loop that shows the latest topic with the author and time under the "Freshness" column.

    The only problem with this so far is it will still show the time and the word by in the loop even if there isn't a post made. So if you have a forum that has no topics, it will still show this. I'm sure we could tweak the code to not do this with conditionals. It also doesn't seem to show locked or sticky topics if they are the most recently posted. I'm wondering if we can clean the code up a bit to fix these problems?

  • Joshua

    After investigating, I've changed my code to this:
    This works but it still doesn't include topics that are marked as "closed" .

    <li class="bbp-forum-freshness">
    
    		<?php do_action( 'bbp_theme_before_forum_freshness_link' ); ?>
    
    		<div class="bbp-forum-last-topic-name"><a href="<?php bbp_forum_last_topic_permalink(); ?>"><?php bbp_forum_last_topic_title(); ?></a></div>
    
    		<?php do_action( 'bbp_theme_after_forum_freshness_link' ); ?>
    
    				<div class="bbp-topic-meta">
    
    			<?php do_action( 'bbp_theme_before_topic_author' ); ?>
    
    			<span class="bbp-topic-freshness-author">by<?php bbp_author_link( array( 'post_id' => bbp_get_forum_last_active_id(), 'size' => 14 ) ); ?></span>
    			<?php do_action( 'bbp_theme_after_topic_author' ); ?>
    
    		</div>
    
    	</li>

    This is what it looks like
    https://ibb.co/k03rkH

  • Joshua

    Hi Kasia Swiderska ,
    I think I used the wrong term "excerpts" in my original post. I basically wanted to replace the "freshness" column with the actual latest topic.

    Here is my code for the loop-single-topic.php

    <?php
    
    /**
     * Topics Loop - Single
     *
     * @package bbPress
     * @subpackage Theme
     */
    
    ?>
    
    <ul id="bbp-topic-<?php bbp_topic_id(); ?>" <?php bbp_topic_class(); ?>>
    
    	<li class="bbp-topic-title">
    
    		<?php if ( bbp_is_user_home() ) : ?>
    
    			<?php if ( bbp_is_favorites() ) : ?>
    
    				<span class="bbp-row-actions">
    
    					<?php do_action( 'bbp_theme_before_topic_favorites_action' ); ?>
    
    					<?php bbp_topic_favorite_link( array( 'before' => '', 'favorite' => '+', 'favorited' => '&times;' ) ); ?>
    
    					<?php do_action( 'bbp_theme_after_topic_favorites_action' ); ?>
    
    				</span>
    
    			<?php elseif ( bbp_is_subscriptions() ) : ?>
    
    				<span class="bbp-row-actions">
    
    					<?php do_action( 'bbp_theme_before_topic_subscription_action' ); ?>
    
    					<?php bbp_topic_subscription_link( array( 'before' => '', 'subscribe' => '+', 'unsubscribe' => '&times;' ) ); ?>
    
    					<?php do_action( 'bbp_theme_after_topic_subscription_action' ); ?>
    
    				</span>
    
    			<?php endif; ?>
    
    		<?php endif; ?>
    
    		<?php do_action( 'bbp_theme_before_topic_title' ); ?>
    
    		<a class="bbp-topic-permalink" href="<?php bbp_topic_permalink(); ?>"><?php bbp_topic_title(); ?></a>
    
    		<?php do_action( 'bbp_theme_after_topic_title' ); ?>
    
    		<?php bbp_topic_pagination(); ?>
    
    		<?php do_action( 'bbp_theme_before_topic_meta' ); ?>
    
    		<p class="bbp-topic-meta">
    
    			<?php do_action( 'bbp_theme_before_topic_started_by' ); ?>
    
    			<span class="bbp-topic-started-by"><?php printf( __( 'Started by: %1$s', 'bbpress' ), bbp_get_topic_author_link( array( 'size' => '14' ) ) ); ?></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>', 'bbpress' ), 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; ?>
    
    		</p>
    
    		<?php do_action( 'bbp_theme_after_topic_meta' ); ?>
    
    		<?php bbp_topic_row_actions(); ?>
    
    	</li>
    
    	<li class="bbp-topic-voice-count"><?php bbp_topic_voice_count(); ?></li>
    
    	<li class="bbp-topic-reply-count"><?php bbp_show_lead_topic() ? bbp_topic_reply_count() : bbp_topic_post_count(); ?></li>
    
    	<li class="bbp-topic-freshness">
    
    		<?php do_action( 'bbp_theme_before_topic_freshness_link' ); ?>
    
    		<?php bbp_topic_freshness_link(); ?>
    
    		<?php do_action( 'bbp_theme_after_topic_freshness_link' ); ?>
    
    		<p class="bbp-topic-meta">
    
    			<?php do_action( 'bbp_theme_before_topic_freshness_author' ); ?>
    
    			<span class="bbp-topic-freshness-author"><?php bbp_author_link( array( 'post_id' => bbp_get_topic_last_active_id(), 'size' => 14 ) ); ?></span>
    
    			<?php do_action( 'bbp_theme_after_topic_freshness_author' ); ?>
    
    		</p>
    	</li>
    
    </ul><!-- #bbp-topic-<?php bbp_topic_id(); ?> -->
  • Kasia Swiderska

    Hello Joshua,

    There is nothing wrong with your code. I did few testes and bbPress by default does not show closed topics on forum list (as in freshness col).
    Unfortunately I haven't found any way to change that default behavior. I've asked if any of our developers would know if there is way to change that, but I suggest also asking this on the bbPress forum in case someone will already know the asnwer https://bbpress.org/forums/

    kind regards,
    Kasia