Skip to content

Instantly share code, notes, and snippets.

@ntwb
Created July 18, 2012 01:22
Show Gist options
  • Save ntwb/3133449 to your computer and use it in GitHub Desktop.
Save ntwb/3133449 to your computer and use it in GitHub Desktop.
bbPress custom bbp_list_forums
<?php
// Custom bbp_list_forums bbPress code by @Lynq
// Demo: http://teamoverpowered.com/forums/
// Code Discussion: http://bbpress.org/forums/topic/customising-bbp_list_forums-last-poster-block/
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' => '<ul class="bbp-forums-list">',
'after' => '</ul>',
'link_before' => '<li class="bbp-forum">',
'link_after' => '</li>',
'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 = "<div class='freshness-forum-link'>" . BBP_Default::custom_get_last_poster_block( $sub_forum->ID ) . "</div>";
}
// Build this sub forums link
if ($i % 2) { $class = "odd-forum-row"; } else { $class = "even-forum-row"; }
$output .= "<li class='{$class}'><ul>" . $link_before . '<a href="' . $permalink . '" class="bbp-forum-link">' . $title . '</a>' . $counts . $freshness_link . $link_after . "</ul></li>";
}
// Output the list
echo apply_filters( 'bbp_list_forums', $before . $output . $after, $args );
}
}
// Then I call the function like this
BBP_Default::custom_bbp_list_forums( array (
'before' => '<ul class="bbp-forums-list">',
'after' => '</ul>',
'link_before' => '<li class="bbp-forum">',
'link_after' => '</li>',
'count_before' => '<div class="topic-reply-counts">Topics: ',
'count_after' => '</div>',
'count_sep' => '<br />Posts: ',
'separator' => '<div style="clear:both;"></div>',
'forum_id' => '',
'show_topic_count' => true,
'show_reply_count' => true,
'show_freshness_link' => true,
));
@ramonov
Copy link

ramonov commented Jan 29, 2014

where shall i put it ? i mean file name from bbpress plugin?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment