Advertisement
Guest User

Custom bbp_list_forums bbPress

a guest
Jul 17th, 2012
951
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public function custom_bbp_list_forums( $args = '' ) {
  2.  
  3.         // Define used variables
  4.         $output = $sub_forums = $topic_count = $reply_count = $counts = '';
  5.         $i = 0;
  6.         $count = array();
  7.  
  8.         // Defaults and arguments
  9.         $defaults = array (
  10.             'before'            => '<ul class="bbp-forums-list">',
  11.             'after'             => '</ul>',
  12.             'link_before'       => '<li class="bbp-forum">',
  13.             'link_after'        => '</li>',
  14.             'count_before'      => ' (',
  15.             'count_after'       => ')',
  16.             'count_sep'         => ', ',
  17.             'separator'         => ', ',
  18.             'forum_id'          => '',
  19.             'show_topic_count'  => true,
  20.             'show_reply_count'  => true,
  21.             'show_freshness_link'  => true,
  22.         );
  23.         $r = bbp_parse_args( $args, $defaults, 'list_forums' );
  24.         extract( $r, EXTR_SKIP );
  25.  
  26.         // Bail if there are no subforums
  27.         if ( !bbp_get_forum_subforum_count( $forum_id ) )
  28.             return;
  29.  
  30.         // Loop through forums and create a list
  31.         $sub_forums = bbp_forum_get_subforums( $forum_id );
  32.         if ( !empty( $sub_forums ) ) {
  33.  
  34.             // Total count (for separator)
  35.             $total_subs = count( $sub_forums );
  36.             foreach ( $sub_forums as $sub_forum ) {
  37.                 $i++; // Separator count
  38.  
  39.                 // Get forum details
  40.                 $count     = array();
  41.                 $show_sep  = $total_subs > $i ? $separator : '';
  42.                 $permalink = bbp_get_forum_permalink( $sub_forum->ID );
  43.                 $title     = bbp_get_forum_title( $sub_forum->ID );
  44.  
  45.                 // Show topic count
  46.                 if ( !empty( $show_topic_count ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
  47.                     $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
  48.                 }
  49.  
  50.                 // Show reply count
  51.                 if ( !empty( $show_reply_count ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
  52.                     $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
  53.                 }
  54.  
  55.                 // Counts to show
  56.                 if ( !empty( $count ) ) {
  57.                     $counts = $count_before . implode( $count_sep, $count ) . $count_after;
  58.                 }
  59.                
  60.                 if ( !empty( $show_freshness_link ) ) {
  61.                     $freshness_link = "<div class='freshness-forum-link'>" . BBP_Default::custom_get_last_poster_block( $sub_forum->ID ) . "</div>";
  62.                 }
  63.  
  64.                 // Build this sub forums link
  65.                 if ($i % 2) { $class = "odd-forum-row"; } else { $class = "even-forum-row"; }
  66.                 $output .= "<li class='{$class}'><ul>" . $link_before . '<a href="' . $permalink . '" class="bbp-forum-link">' . $title . '</a>' . $counts . $freshness_link . $link_after . "</ul></li>";
  67.             }
  68.  
  69.             // Output the list
  70.             echo apply_filters( 'bbp_list_forums', $before . $output . $after, $args );
  71.         }
  72.     }
  73.  
  74. // Then I call the function like this
  75. BBP_Default::custom_bbp_list_forums( array (
  76.         'before'            => '<ul class="bbp-forums-list">',
  77.         'after'             => '</ul>',
  78.         'link_before'       => '<li class="bbp-forum">',
  79.         'link_after'        => '</li>',
  80.         'count_before'      => '<div class="topic-reply-counts">Topics: ',
  81.         'count_after'       => '</div>',
  82.         'count_sep'         => '<br />Posts: ',
  83.         'separator'         => '<div style="clear:both;"></div>',
  84.         'forum_id'          => '',
  85.         'show_topic_count'  => true,
  86.         'show_reply_count'  => true,
  87.         'show_freshness_link' => true,
  88.     ));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement