bbp_list_forums

Output a list of forums (can be used to list subforums).

Description

bbp_list_forums( (string) $args = '' ); 

Parameters (1)

0. $args — Optional. (string) => ''
The function supports these args: - before: To put before the output. Defaults to
    ' - after: To put after the output. Defaults to
- link_before: To put before every link. Defaults to
  • ' - link_after: To put after every link. Defaults to
  • - separator: Separator. Defaults to , - forum_id: Forum id. Defaults to '' - show_topic_count - To show forum topic count or not. Defaults to true - show_reply_count - To show forum reply count or not. Defaults to true

    Usage

    1. if ( !function_exists( 'bbp_list_forums' ) ) { 
    2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/template.php'; 
    3. $args = ''; 
    4.  
    5. // NOTICE! Understand what this does before running. 
    6. $result = bbp_list_forums($args); 
    7.  

    Defined (1)

    The function is defined in the following location(s).

    /includes/forums/template.php  
    1. function 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. // 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.  
    38. // Show topic count 
    39. if ( !empty( $r['show_topic_count'] ) && !bbp_is_forum_category( $sub_forum->ID ) ) { 
    40. $count['topic'] = bbp_get_forum_topic_count( $sub_forum->ID ); 
    41.  
    42. // Show reply count 
    43. if ( !empty( $r['show_reply_count'] ) && !bbp_is_forum_category( $sub_forum->ID ) ) { 
    44. $count['reply'] = bbp_get_forum_reply_count( $sub_forum->ID ); 
    45.  
    46. // Counts to show 
    47. if ( !empty( $count ) ) { 
    48. $counts = $r['count_before'] . implode( $r['count_sep'], $count ) . $r['count_after']; 
    49.  
    50. // Build this sub forums link 
    51. $output .= $r['link_before'] . '<a href="' . esc_url( $permalink ) . '" class="bbp-forum-link">' . $title . $counts . '</a>' . $show_sep . $r['link_after']; 
    52.  
    53. // Output the list 
    54. echo apply_filters( 'bbp_list_forums', $r['before'] . $output . $r['after'], $r );