Skip to:
Content
Pages
Categories
Search
Top
Bottom

Customising bbp_list_forums – Last Poster Block


  • Lynq
    Participant

    @lynq

    Hey guys,

    I am putting up a topic to show how I have created the layout on http://teamoverpowered.com/forums/

    My aim when creating the theme was to try and create a last poster block that would work throughout the forums and sub forums list.

    custom_bbp_list_forums – this function creates the sub forums under the main forum

    public function custom_bbp_list_forums( $args = '' ) {
    
        // Define used variables
        $output = $sub_forums = $topic_count = $reply_count = $counts = '';
        $i = 0;
        $count = array();
    
        // Defaults and arguments
        $defaults = array (
            'before'            => '',
            'after'             => '',
            'link_before'       => '',
            'link_after'        => '',
            'count_before'      => ' (',
            'count_after'       => ')',
            'count_sep'         => ', ',
            'separator'         => ', ',
            'forum_id'          => '',
            'show_topic_count'  => true,
            'show_reply_count'  => true,
            'show_freshness_link'  => true,
        );
        $r = bbp_parse_args( $args, $defaults, 'list_forums' );
        extract( $r, EXTR_SKIP );
    
        // Bail if there are no subforums
        if ( !bbp_get_forum_subforum_count( $forum_id ) )
            return;
    
        // Loop through forums and create a list
        $sub_forums = bbp_forum_get_subforums( $forum_id );
        if ( !empty( $sub_forums ) ) {
    
            // Total count (for separator)
            $total_subs = count( $sub_forums );
            foreach ( $sub_forums as $sub_forum ) {
                $i++; // Separator count
    
                // Get forum details
                $count     = array();
                $show_sep  = $total_subs > $i ? $separator : '';
                $permalink = bbp_get_forum_permalink( $sub_forum->ID );
                $title     = bbp_get_forum_title( $sub_forum->ID );
    
                // Show topic count
                if ( !empty( $show_topic_count ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
                    $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
                }
    
                // Show reply count
                if ( !empty( $show_reply_count ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
                    $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
                }
    
                // Counts to show
                if ( !empty( $count ) ) {
                    $counts = $count_before . implode( $count_sep, $count ) . $count_after;
                }
    
                if ( !empty( $show_freshness_link ) ) {
                    $freshness_link = "" . BBP_Default::teamop_get_last_poster_block( $sub_forum->ID ) . "";
                }
    
                // Build this sub forums link
                if ($i % 2) { $class = "odd-forum-row"; } else { $class = "even-forum-row"; }
                $output .= "" . $link_before . '<a href="' . $permalink . '">' . $title . '</a>' . $counts . $freshness_link . $link_after . "";
            }
    
            // Output the list
            echo apply_filters( 'bbp_list_forums', $before . $output . $after, $args );
        }
    }
    

    I then call that function inside loop-single-forum.php like so:

    BBP_Default::custom_bbp_list_forums( array (
            'before'            => '',
            'after'             => '',
            'link_before'       => '',
            'link_after'        => '',
            'count_before'      => 'Topics: ',
            'count_after'       => '',
            'count_sep'         => 'Posts: ',
            'separator'         => '',
            'forum_id'          => '',
            'show_topic_count'  => true,
            'show_reply_count'  => true,
            'show_freshness_link' => true,
            ));
    

    Inside the first function I am also calling a second custom function called custom_get_last_poster_block

    function custom_get_last_poster_block( $subforum_id = "" ) {
    
                if ( !empty( $subforum_id ) ) {
                    $output = "";
                    $output .= "<a href='". bbp_get_forum_last_topic_permalink( $subforum_id ) ."'>" . bbp_get_topic_last_reply_title( bbp_get_forum_last_active_id( $subforum_id ) ) . "</a>";
                    $output .= "";
                    $output .= "by ";
                    $output .= bbp_get_author_link( array( "post_id" => $subforum_id, "size" => 14 ) );
                    $output .= "";
                    $output .= "";
                    $output .= bbp_get_forum_last_active_time( $subforum_id );
                    $output .= "";
                } else {
                    $output = "";
                    $output .= "<a href='". bbp_get_forum_last_topic_permalink() ."'>" . bbp_get_topic_last_reply_title( bbp_get_forum_last_active_id() ) . "</a>";
                    $output .= "";
                    $output .= "by ";
                    $output .= bbp_get_author_link( array( "post_id" => bbp_get_forum_last_active_id(), "size" => 14 ) );
                    $output .= "";
                    $output .= "";
                    $output .= bbp_get_forum_last_active_time( bbp_get_forum_last_active_id() );
                    $output .= "";
                }
    
                return $output;
    
            }
    

    This then creates my sub forum list, I added some extra classes in I can hook onto and display:none if need. I decided when creating me theme that I would get as much information showing as possible, then just use CSS to customise it.

    The final functions is one I call inside loop-single-topic.php.

        public function custom_get_last_poster_block_topics() {
    
                $output .= "";
                $output .= bbp_get_author_link( array( "post_id" => bbp_get_forum_last_active_id(), "size" => 14 ) );
                $output .= "";
                $output .= "";
                $output .= bbp_get_topic_last_active_time( bbp_get_topic_last_active_id() );
                $output .= "";
    
            return $output;
    
        }
    

    This is my final function and it just adds the last poster block inside the topics list.

    If you need any more help then let me know.

    UPDATE: Please see the following topic for updated code

    http://bbpress.org/forums/topic/i-have-created-a-bbpress-starter-theme-with-a-phpbb-look-and-feel/

Viewing 13 replies - 26 through 38 (of 38 total)

  • Phill
    Participant

    @sharkbites

    Hi Lynq, thank you for this code! I would have never figured this out on my own.

    I have a question. I’ve pasted these functions into my bbpress-functions.php and called the custom forum list function in my single-loop-forum.php file but for some reason I keep getting a parse error telling me that there was an unexpected T_Public. Do you know how I would fix this? Is there a certain place in the bbpress-functions.php file I’m supposed to paste that code?

    Thanks for the help!


    DFC005
    Participant

    @dfc005

    Hope someone can point me in the right direct with this one.

    My forum homepage looks like thus: http://www.zerotackle.com/discussion/

    And works perfectly. If I drill into a forum to see the topics, it looks like this: http://www.zerotackle.com/discussion/forums/nrl/general-discussion/

    Perfect!

    My problem is if I go into a category, I don’t see any topics under the subforum. Here: http://www.zerotackle.com/discussion/forums/nrl/

    Can anyone point me in the right direction as to why?


    jmosterd
    Participant

    @jmosterd

    Where do i have to past everything?


    jmosterd
    Participant

    @jmosterd

    how can i make this work? tutorial?


    Shmoo
    Participant

    @macpresss

    The first block goes inside your functions.php i guess,

    And all others you have to add where to show – inside your template files. example loop-single-forum.php

    That fie can be found in your bbpress plugins directory.
    wp-content / bbpress / templates / defaults / bbpress / ** here **

    Don’t edit files from the bbpress folder inside your plugins folder because those will be overwritten when bbPress updates.
    Just copy files that you need to edit towards your theme folder just like this:

    wp-content / themes / [ your theme name ] / bbpress / ** here **


    Rivac0m
    Participant

    @rivac0m

    So I followed what I thought was the correct order but it doesn’t seem to work as intended. Are we replacing all of loop-single-forum.php with the new code? or only a portion of it?

    Also if this is all theme related(minus the function call), couldn’t someone just upload their theme for others to use?


    mst
    Participant

    @mst

    Thank you @lynq for the initiative writing this up :)

    If you like to show the sub-forum description you could use get_post() and modify the code from @lynq to fetch it.

    Something like this:

    $get_sub_desc = get_post( $sub_forum->ID );
    $show_sub_desc = $get_sub_desc->post_content;

    then add $show_sub_desc to the output.


    CC-Cailin
    Participant

    @cc-cailin

    It seems like most people who are having issues are using buddypress.
    I am using buddypress, and I end up getting a blank screen as soon as I add the first function. Any help?


    FreeWPress
    Participant

    @freewpress

    @lynq
    Hi, i have see in your forum after user avatar, the user post count, how to do for have this? I have tried more solutions but nothig works fine, have you solution?

    Thanks!!


    Newo1t
    Participant

    @newo1t

    Hi, I’ve a error of the first line when you declare the function.
    “syntax error, unexpected T_PUBLIC”

    Can you fix this ?

    Thank’s !


    Aqeart
    Participant

    @aqeart

    Thank you for this amazing addon.
    I’m sorry but I really don’t know how to get this code working. I tried to copy-paste the first github file to my bbpress-functions.php, however my website got crashed due to a string error. Can you please explain a beginner like me how to do that from scratch?
    Thanks!


    Oken
    Participant

    @oken

    I was directed to this topic when I asked about the particular features this customization was said to have solved. I too have also tried to follow the directions and entered the codes from this post, but to no avail. I get the same crashed website.

    Here’s where I put each peace of code. Maybe someone can point out where I went all wrong.

    http://pastebin.com/GLhCHYze – I put this in my functions.php file.

    http://pastebin.com/8K0pkKs5 – I put this in my theme’s bbpress/loop-single-forum.php file.

    http://pastebin.com/FGptZmiQ – I put this in my theme’s bbpress/loop-single-topic.php file.

    As someone mentioned, The creator of this code seems to have a stand alone version of bbpress instead of the plugin type that I use with Buddypress. Perhaps this is why it hasn’t worked for a few folks. I’d be interested to hear from someone that has Buddypress installed on their copy of wordpress and have successfully been able to make the customization work for them in their template files. If we could hear how they went about installing the code, it might help out some that might be stuck.

    Many thanks in advance! :)

    I am going to close this topic as we should be really using the following topic ;)
    (My bad, I may have pointed a few people to this one recently)

    http://bbpress.org/forums/topic/i-have-created-a-bbpress-starter-theme-with-a-phpbb-look-and-feel/

Viewing 13 replies - 26 through 38 (of 38 total)

The topic ‘Customising bbp_list_forums – Last Poster Block’ is closed to new replies.