Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to display topic freshness attributes under topic title?


  • Robkk
    Moderator

    @robkk

    im trying to put a function in loop-single-topic.php right after

    <?php do_action( ‘bbp_theme_before_topic_started_by’ ); ?>

    Replacing the whole (Started By: “user” in “forum” function)

    Im trying to make the new function display as (Last Post “freshness time ago” By “User”)

    I dont know anything about php and how to use it , right now im basically just looking at each function and see how it works.

    The best i got right now is pretty much copy and pasted from the freshness column functions.

    This is the best i have

    <span class=”bbp-last-post-by-author”><?php printf( __( ‘Last Post %1$s’, ‘bbpress’ ), bbp_get_topic_freshness_link( array() ) ); ?></span>

    I still need to display this

    <?php bbp_author_link( array( ‘post_id’ =>bbp_get_topic_last_active_id()

    but i dont know how to hook it all together, please help.

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

  • Robin W
    Moderator

    @robin-w

    Sounds like you’re further through hacking the code than most people get !

    ok, just in case you haven’t already seen it, if you’re changing the template files, you should create a bbpress directory in the root of your (child)theme, and copy the files there. bbPress will then use these instead, and they won’t get overwritten by upgrades to bbpress. You should also have a child theme, and put them in there rather than someone else’s theme, and then theme updates won’t overwrite them either!

    see

    Step by step guide to setting up a bbPress forum – part 2

    and

    https://codex.bbpress.org/step-by-step-guide-to-setting-up-a-bbpress-forum-part-3/ section 3

    I presume you’ve tried the code? That’s the other great thing about using the bbpress folder in your child theme, you can just delete the server version and it goes back to the default one.

    If so where is it falling over?

    can you copy the lines between

    <?php do_action( 'bbp_theme_before_topic_started_by' ); ?>
    

    and

    `<?php do_action( ‘bbp_theme_after_topic_started_by’ ); ?>

    and paste them into here, and I’ll take a look

    I’m out today, but if I get a chance later I’ll then run it and debug for you.


    Robkk
    Moderator

    @robkk

    Yeah i have been using a child theme,

    I havent put every file from bbpress in my child theme

    Im just making small changes to the template files and only throw in the ones that i changed into my theme.

    And i use my themes custom css plugin for css changes.

    I really dont have anything to debug, i just have bits of php to try to make my desired function

    Like i know bbp_get_topic_freshness_link , shows the time ago of the last post

    And that <?php bbp_author_link( array( 'post_id' =>bbp_get_topic_last_active_id() gets ahold of the author of the last post in a topic

    <?php printf( __( 'Last Post: %1$s' lets me have my custom text with the attributes from the function

    I just dont know how to put that all together to get the function that i want

    Right now all in my function is

    <?php do_action( 'bbp_theme_before_topic_started_by' ); ?>
    
    <span class="bbp-last-post-by-author"><?php printf( __( 'Last Post: %1$s', 'bbpress' ),bbp_get_topic_freshness_link( array() ) ); ?></span>
    
    			<?php do_action( 'bbp_theme_after_topic_started_by' ); ?>

    Robin W
    Moderator

    @robin-w

    “I havent put every file from bbpress in my child theme ”

    yes that’s fine, you only need to put in files that you have changed.

    I’ll look at the rest of your comments shortly !


    Robin W
    Moderator

    @robin-w

    you were pretty much there

    the following, which is just two lines nicked from elsewhere and joined by a ‘by’ text should do what you want

    <span class="bbp-last-post-by-author"><?php printf( __( 'Last Post: %1$s', 'bbpress' ),bbp_get_topic_freshness_link( array() ) ); ?></span>
    <?php _e(' by ', 'bbp'); ?>
    <span class="bbp-topic-freshness-author"><?php bbp_author_link( array( 'post_id' => bbp_get_topic_last_active_id(), 'size' => 14 ) ); ?></span>
    

    Come back if that’s not what you wanted !


    Robkk
    Moderator

    @robkk

    @robin-w worked like a charm, thank you very much for the help!


    Robin W
    Moderator

    @robin-w

    you’re welcome !!


    TheDream18
    Participant

    @oanhtran1804

    Hello,

    I’m not good at code. Can you please step by step what to do?

    I added following code to function.php childe-theme, it leaved me a blank page.

    <span class=”bbp-last-post-by-author”><?php printf( __( ‘Last Post: %1$s’, ‘bbpress’ ),bbp_get_topic_freshness_link( array() ) ); ?></span>
    <?php _e(‘ by ‘, ‘bbp’); ?>
    <span class=”bbp-topic-freshness-author”><?php bbp_author_link( array( ‘post_id’ => bbp_get_topic_last_active_id(), ‘size’ => 14 ) ); ?></span>

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