bbp_list_forums( mixed $args = '' )
Output a list of forums (can be used to list subforums)
Description
Parameters
- $args
-
(Optional) The function supports these args: - before: To put before the output. Defaults to
<ul class="bbp-forums">
- after: To put after the output. Defaults to</ul>
- link_before: To put before every link. Defaults to<li class="bbp-forum">
- link_after: To put after every link. Defaults to</li>
- 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 trueDefault value: ''
Source
File: bp-forums/forums/template.php
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 | function bbp_list_forums( $args = '' ) { // Define used variables $output = $sub_forums = $topic_count = $reply_count = $counts = '' ; $i = 0; $count = array (); // Parse arguments against default values $r = bbp_parse_args( $args , 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, ), 'list_forums' ); // Loop through forums and create a list $sub_forums = bbp_forum_get_subforums( $r [ '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 ? $r [ 'separator' ] : '' ; $permalink = bbp_get_forum_permalink( $sub_forum ->ID ); $title = bbp_get_forum_title( $sub_forum ->ID ); // Show topic count if ( ! empty ( $r [ '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 ( $r [ '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 = $r [ 'count_before' ] . implode( $r [ 'count_sep' ], $count ) . $r [ 'count_after' ]; } // Build this sub forums link $output .= $r [ 'link_before' ] . '<a href="' . esc_url( $permalink ) . '" class="bbp-forum-link">' . $title . $counts . '</a>' . $show_sep . $r [ 'link_after' ]; } // Output the list echo apply_filters( 'bbp_list_forums' , $r [ 'before' ] . $output . $r [ 'after' ], $r ); } } |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.