Advertisement
wido

BbPress add subforum description

Mar 12th, 2016
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.15 KB | None | 0 0
  1. function xx_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.     // Parse arguments against default values
  9.     $r = bbp_parse_args( $args, 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.     ), 'list_forums' );
  22.  
  23.     // Loop through forums and create a list
  24.     $sub_forums = bbp_forum_get_subforums( $r['forum_id'] );
  25.     if ( !empty( $sub_forums ) ) {
  26.  
  27.         // Total count (for separator)
  28.         $total_subs = count( $sub_forums );
  29.         foreach ( $sub_forums as $sub_forum ) {
  30.             $i++; // Separator count
  31.  
  32.             // Get forum details
  33.             $count     = array();
  34.             $show_sep  = $total_subs > $i ? $r['separator'] : '';
  35.             $permalink = bbp_get_forum_permalink( $sub_forum->ID );
  36.             $title     = bbp_get_forum_title( $sub_forum->ID );
  37.             $content   = bbp_get_forum_content($sub_forum->ID) ;
  38.  
  39.             // Show topic count
  40.             if ( !empty( $r['show_topic_count'] ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
  41.                 $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID );
  42.             }
  43.  
  44.             // Show reply count
  45.             if ( !empty( $r['show_reply_count'] ) && !bbp_is_forum_category( $sub_forum->ID ) ) {
  46.                 $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID );
  47.             }
  48.  
  49.             // Counts to show
  50.             if ( !empty( $count ) ) {
  51.                 $counts = $r['count_before'] . implode( $r['count_sep'], $count ) . $r['count_after'];
  52.             }
  53.  
  54.             // Build this sub forums link
  55.             $output .= $r['link_before'] . '<a href="' . esc_url( $permalink ) . '" class="bbp-forum-link">' .
  56.                        $title . $counts . '</a>' .
  57.                        $show_sep . $r['link_after'] .
  58.                        '<div class="bbp-forum-content">'.$content.'</div>';
  59.         }
  60.  
  61.         // Output the list
  62.         echo $r['before'] . $output . $r['after'];
  63.     }
  64. }
  65. add_filter( 'bbp_list_forums', 'xx_list_forums' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement