Skip to:
Content
Pages
Categories
Search
Top
Bottom

Display Topic Starter label around topic authors avatar in topic replies

  • @robkk

    Moderator

    I wonder if i could add a function that displays a topic starter label for any topic author in a topic.

    It would be cool so that say 5 pages in a topic, you could always know who started the topic if they kept the conversation going.

    I know the function would most likely be put in a theme functions.php but i wonder if it could go into loop-single-reply.php

    I feel like the function would use the topic started by function, mainly get_topic_author

    <span class="bbp-topic-started-by"><?php printf( __( 'Started by: %1$s', 'bbpress' ), bbp_get_topic_author_link( array( 'size' => '14' ) ) ); ?></span>

    IT would be a nice feature to have

    any help??

Viewing 25 replies - 1 through 25 (of 27 total)
  • @robin-w

    Moderator

    This dropped into your functions file puts it in every reply – just thinking about how you’re get every 5th !

    //This function adds the author to the reply
    function reply_display_author () {
    	if( get_post_type() == 'reply' ) {
    	echo '<span class="bbp-topic-started-by">' ;
    	printf( __( 'Topic started by: %1$s', 'bbpress' ), bbp_get_topic_author_link( array( 'size' => '14' ) )) ; 
    	echo '</span>' ;
    	}
    	else {
    	return ;
    	}
    	}
    add_action ('bbp_theme_before_reply_content', 'reply_display_author') ;

    @robin-w

    Moderator

    ok, may be a little rough, but seems to work

    put this in your functions file

    //This function adds the author to the reply
    function reply_display_author () {
    	global $countr ;
    	if ($countr == 5 ) {
    	echo '<span class="bbp-topic-started-by">' ;
    	printf( __( 'Topic started by: %1$s', 'bbpress' ), bbp_get_topic_author_link( array( 'size' => '14' ) )) ; 
    	echo '</span>' ;
    	}
    	else {
    	return ;
    	}
    	}
    	
    	add_action ('bbp_theme_before_reply_content', 'reply_display_author') ;
    	

    and then create a file called bbpress in the root of your theme and copy across loop-replies.php

    then amend from line 42 so that it reads

    <?php if ( bbp_thread_replies() ) : ?>
    
    			<?php bbp_list_replies(); ?>
    			
    			
    		<?php else : ?>
    			<?php global $countr ;
    			$countr=-1 ; ?>
    		
    			<?php while ( bbp_replies() ) : bbp_the_reply(); ?>
    			
    			<?php 
    			$countr ++ ; 
    			
    			<?php bbp_get_template_part( 'loop', 'single-reply' ); ?>
    
    			<?php endwhile; ?>
    			
    			
    		<?php endif; ?>

    seems to do the trick !

    @robkk

    Moderator

    @robin-w hey thanks for helping me out

    and i was using 5 pages as an example

    i would like the topic starter label throughout a topic , for whatever number pages it may have

    so should i basically use this

    //This function adds the author to the reply
    function reply_display_author () {
    	if( get_post_type() == 'reply' ) {
    	echo '<span class="bbp-topic-started-by">' ;
    	printf( __( 'Topic started by: %1$s', 'bbpress' ), bbp_get_topic_author_link( array( 'size' => '14' ) )) ; 
    	echo '</span>' ;
    	}
    	else {
    	return ;
    	}
    	}
    add_action ('bbp_theme_before_reply_content', 'reply_display_author') ;

    with this function instead??

    <?php if ( bbp_thread_replies() ) : ?>
    
    			<?php bbp_list_replies(); ?>
    			
    			
    		<?php else : ?>
    			<?php global $countr ;
    			$countr=-1 ; ?>
    		
    			<?php while ( bbp_replies() ) : bbp_the_reply(); ?>
    			
    			<?php 
    			$countr ++ ;?>
    			
    			<?php bbp_get_template_part( 'loop', 'single-reply' ); ?>
    
    			<?php endwhile; ?>
    			
    			
    		<?php endif; ?>

    @netweb

    Keymaster

    A couple of thoughts, not explicitly what you asked for but are related 😉

    Use bbp_show_lead_topic, here on bbpress.org if you go to a topic with many pages (actually more than 1 page) you always see the original topic at the top of the page.

    And

    Use CSS, take a look at the source of this topic, you’ll notice that any reply by the original topic author has a CSS class topic-author

    @robin-w

    Moderator

    @robkk

    ‘I would like the topic starter label throughout a topic , for whatever number pages it may have ‘

    So Stephen’s advice is good then, follow his link and put the topic at the start of each page !

    @robkk

    Moderator

    @netweb thanks for the reply
    i might do that function if i cant get the exact function im looking for

    i did find an example of a bbpress forum using exactly what i want though

    if you look at any other participant in the forum they do not have the topic author label

    so its exactly what im looking for.

    im trying to think of an idea of a function that would do that, but i have no idea how to make a function that does

    if topic author is the same as reply author display label above reply author avatar, or below forum role. IF not the same dont display anything.

    @robkk

    Moderator

    after – i did find an example of a bbpress forum using exactly what i want though

    http://cyberchimps.com/forum-topic/full-width-bbpress-forum/page/2/

    @robin-w

    Moderator

    ‘if topic author is the same as reply author display label above reply author avatar, or below forum role. IF not the same dont display anything. ‘

    Is this now the function you want or is this additional to other stuff – sorry I’m a bit confused !

    @robkk

    Moderator

    @robin-w if it works

    i dont know any other ways to make a function find out if the topic author and reply author have something in common , then in the end result display the label “topic author”

    @robkk

    Moderator

    @robin-w its not anything additional

    im just trying to get the same function cyberchimps forums is using

    @robin-w

    Moderator

    ok, so put this in your functions file

    //This function adds the author to the reply
    function bbp_author_display () {
    	if (bbp_get_reply_author_id() == bbp_get_topic_author_id() ) {
    	echo '<span class="topic-author">' ;
    	echo '<ul><li>' ;
    	echo 'Topic Author' ; 
    	echo '</li></ul></span>' ;
    	}
    	else return ;
    	}
    	
    	add_action ('bbp_theme_after_reply_author_details', 'bbp_author_display') ;

    and this in your style.css

    #bbpress-forums .topic-author{
      background: none repeat scroll 0 0 #5BB75B;
      color: #FFFFFF;
      display: block;
      padding: 5px;
    }
    

    Job done !

    @robkk

    Moderator

    @robin-w Thank you very much!!!

    @robin-w

    Moderator

    great – glad you fixed now – we get there in the end !

    @robkk

    Moderator

    ok my bad for bumping this

    but i changed my mind on how i want the function to display

    is there a way to use if (bbp_get_reply_author_id() == bbp_get_topic_author_id() ) {

    so that it just replaces this code of the reply author name

    div class=reply-author-name><?php bbp_reply_author_link( array( 'show_role' => false, 'type' => 'name' ) ); ?></div>

    to this instead

    div class=topic-starter><?php bbp_reply_author_link( array( 'show_role' => false, 'type' => 'name' ) ); ?></div>

    i just want to change the div class so that if the topic author = reply author it would just show the reply author name in just a different color , kind of like reddit

    i want this because when my site goes to a smaller size i have to remove some attributes like post count , buddypress profile data , user role , and the user avatar at really small screens just so i could make it look nice.

    i want to users to still recognize the topic starter even at smaller screens

    i think a simple filter might do this

    but i dont know where to even start.

    thanks if anybody helps

    @robkk

    Moderator

    nevermind i pretty much add it after the else so it would just return a normal reply author link

    EDIT: didnt get it , still dont know how to construct functions 🙁

    @robin-w

    Moderator

    @robkk – do you still want help or are you now ok?

    @robkk

    Moderator

    @robin-w yeah i still need help

    @robkk

    Moderator

    @robin-w

    Moderator

    ok, ignore the code (it is confusing me)

    So you have a topic started and this displays in the ‘post author’ part an avatar, the topic author name, but no role

    Next someone replies and this displays in the ‘post author’ part an avatar, and the reply author name, but nothing else

    Next is a reply by the original author, and in the ‘post author’ part this display an avatar, and their name in say a green block (and nothing else)

    Is that what you want?

    @robkk

    Moderator

    ok, ignore the code (it is confusing me)

    i understand

    So you have a topic started and this displays in the ‘post author’ part an avatar, the topic author name, but no role

    it should just display the topic author name with a certain color

    Next someone replies and this displays in the ‘post author’ part an avatar, and the reply author name, but nothing else

    yes exactly

    Next is a reply by the original author, and in the ‘post author’ part this display an avatar, and their name in say a green block (and nothing else)

    yes

    Is that what you want?

    just in case heres a picture, zoom with the scroll wheel

    https://drive.google.com/file/d/0B_Ue9ryY5cmYTHhlRkg0a3k4T1U/edit?usp=sharing

    i used a blue because it was the color i had when photoshop was last used

    @robin-w

    Moderator

    ok I looked and it would require a filter to re-write

    bbp_get_reply_author_link

    held in

    bbpress/includes/replies/template.php

    This is beyond the time I currently have available – sorry !

    @robkk

    Moderator

    @robin-w got this done successfully , didnt need a filter the way i did it

    took me about a few minutes when i found how this bit of code is arranged

    http://pastebin.com/39xfPYNb

    @robin-w

    Moderator

    hey great – glad you’re now fixed !

    @robertherold

    Participant

    Hi @robin-w,

    //This function adds the author to the reply
    function bbp_author_display () {
    	if (bbp_get_reply_author_id() == bbp_get_topic_author_id() ) {
    	echo '<span class="topic-author">' ;
    	echo '<ul><li>' ;
    	echo 'Topic Author' ; 
    	echo '</li></ul></span>' ;
    	}
    	else return ;
    	}
    	
    	add_action ('bbp_theme_after_reply_author_details', 'bbp_author_display') ;

    This is a very good code, however, when searching, it puts it on each result. 🙁

    @robin-w

    Moderator

    did you amend loop-replies?

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