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

    I have created a bbPress starter theme with a phpBB look and feel

Viewing 25 replies - 1 through 25 (of 38 total)
  • Nice work, thanks for this 🙂

    Very very well done man. I think many people will find this extremely helpful (or they should) since this is definitely a common request 🙂


    Lynq
    Participant

    @lynq

    Thanks I am glad it will be useful.

    One thing to note is that some of the functions have had the greater than sign escaped, so you can not directly copy it unfortunately.

    Once you have got these functions working then it is just a case of some CSS.

    If you use this then I would be very interested in seeing where and how you styled the pages.

    Good luck all!


    Lynq
    Participant

    @lynq

    Hey guys, I have been debugging a few issues with these functions so I am going to link to each of the functions below in pastebin, should be pretty good to go for copying across I believe.

    Custom bbp_list_forums function. http://pastebin.com/GLhCHYze

    Custom last poster block for forums. http://pastebin.com/8K0pkKs5

    Custom last poster block for topics. http://pastebin.com/FGptZmiQ

    Hope this helps, it is a little clearer on pastebin currently, the code block on bbpress.org likes to change my code for me! :p If you find any issues let me know and I will try and update this topic, also I will get the updates onto my own site.

    Good luck!

    • This reply was modified 11 years, 8 months ago by Lynq.
    • This reply was modified 11 years, 8 months ago by Lynq.

    I just copied each of these into Gists @GitHub for those who use Git…

    Custom bbp_list_forums function. http://pastebin.com/GLhCHYze == https://gist.github.com/3133449

    Custom last poster block for forums. http://pastebin.com/8K0pkKs5 == https://gist.github.com/3133450

    Custom last poster block for topics. http://pastebin.com/FGptZmiQ == https://gist.github.com/3133451

    • This reply was modified 11 years, 8 months ago by Stephen Edgar.

    You need to add open php tags at the topf of the gists so the color syntax will show up 🙂

    Fixed 😉 I am still soooo new to the world of Git, Gists, GitHub and version control but love it soooo much 🙂


    Lynq
    Participant

    @lynq

    I am wanting to try out git but it all comes down to having time to just play around with it.

    You will notice there is a slight difference between the gists and my initial functions (at the very start of this topic), this is because I found out my last poster block was not quite displaying correctly, which it now is and the gists are the correct place to be looking for the functions.

    Thanks for adding them netweb.

    Just update your originals at pastebin and ping me and I will update them from the changes.

    I came upon this only a couple of days ago…. I only know the Git basics and that is 90% of what I need 🙂

    Got 15 minutes and want to learn Git?
    http://try.github.com/


    Lynq
    Participant

    @lynq

    Ahh no sorry I meant the very original functions I put one. The ones in the gists you made are the most up to date 🙂

    Thanks for the link I am going through that right now!

    This looks like exactly what I’ve been searching for! Can you please explain a bit more how to implement it? Do i need to change the bbp-forum-remplate.php version of the function?

    Thanks!
    Matt


    Lynq
    Participant

    @lynq

    No you will never need to touch the core code.

    You put these functions inside bbpress-functions.php then you can call these functions inside your template files. like: BBP_Default::custom_bbp_list_forums();

    Inside loop-forum-single.php you change where it is calling the function to the new custom function.

    If you need any more help let me know, good luck!

    I don’t have a bbpress-functions.php in my wordpress theme (I forgot to mention that I’m using bbpress as a plugin.) is it just a file that I make myself? also, do I just include() it? or does bbpress have some way of connecting to it?

    Thank you very much for all your help!

    Hey! I got it to work! I just made a custom plugin with the BBP_Default class that you had in those public functions and just changed

    $r = bbp_parse_args( $args, $defaults, 'list_forums' );
    

    to

    $r = wp_parse_args( $args, $defaults, 'list_forums' );
    

    to make it work with the wordpress plugin version of bbp.

    You should definitely submit this as a plugin!

    encountered an issue. I get this error:

    > Warning: Cannot modify header information – headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/wordpress/wp-content/plugins/bbpress-functions.php:12) in /Applications/XAMPP/xamppfiles/htdocs/wordpress/wp-includes/pluggable.php on line 934

    Any idea what’s going on?

    problem was that I had white space. Problem solved


    Jeff
    Member

    @splatterrific

    @matt_sich is your plugin up on the repository? Would love for me (and I am sure many others) to get a hold of it 🙂


    Lynq
    Participant

    @lynq

    You could create it as a plugin but it would probably be very difficult to hook into the bbp_list_forums function and make it run your own instead, if anyone could give me an idea on how to do that I would be happy to make it into a plugin.

    Have fun guys and keep on coding!

    Thank you very much it helped me a lot.

    It would be perfect for me if I can add the description of the forum.

    Is there a method to display the description of each of the forums in the list which is generated by bbp_list_forums();

    Thanks again.


    HTK
    Participant

    @htk

    Although I’m not going for that look, nice work man. I’m looking for a style like this site has. Where the Forum (categories) are on the left and melting pot in the middle.

    Nice looking site by the way.


    eBierek
    Participant

    @ebierek

    Hi, I like what Lynq did with the forum structure on http://teamoverpowered.com/forums. Anyone up for doing sth similar for me on a site? Paid work that is. In need of some backup for a membership site with forum. Not sure this is the right forum to post this, but if interested contact me at (hello at pixelstreet dot se). Many thanks/e


    brunski
    Participant

    @brunski

    I must be doing something wrong when I enter the first bit of code into the bbpres-functions.php file of the them I get an error regarding the public function error. Can someone give me an idea on where I am making a mistake?


    Ommy
    Participant

    @bounomid

    I am using wordpress+buddypress+bbpress I couldnt make it work, can anyone help ?

    • This reply was modified 11 years, 5 months ago by Ommy.

    Ommy
    Participant

    @bounomid

    no one use this codes for buddypress? it is big issue for most people to have seperate blockss. help help 😀


    DramaticBaby
    Participant

    @dramaticbaby

    Thank you for this post Lynq, appreciated! I’m trying to modify the bbp-list-forums function to print the subforums descriptions, but I’m just getting multiple descriptions of the parent forum (One for each subforum).

    I’ve tried using the_content() function inside my-bbp-list-forums.

    Got any solution on this one? Or am I completely off? 😛

Viewing 25 replies - 1 through 25 (of 38 total)
  • The topic ‘Customising bbp_list_forums – Last Poster Block’ is closed to new replies.
Skip to toolbar