Skip to:
Content
Pages
Categories
Search
Top
Bottom

bbp_forum_class('clearfix') doesn't work


  • niuserre
    Participant

    @niuserre

    bbPress 2.4
    WP 3.6.1
    running on localhost

    I need to add a class to bb_forum_class and since 2.1 I thought that this should work:

    <?php bbp_forum_class('clearfix'); ?>

    But it’s not adding the class, can anyone tell me what I’m doing wrong please?

    I think the relevant bit of core for this is:

    function bbp_get_forum_class( $forum_id = 0, $classes = array() ) {
    		$bbp       = bbpress();
    		$forum_id  = bbp_get_forum_id( $forum_id );
    		$count     = isset( $bbp->forum_query->current_post ) ? $bbp->forum_query->current_post : 1;
    		$classes   = (array) $classes;
    
    		// Get some classes
    		$classes[] = 'loop-item-' . $count;
    		$classes[] = ( (int) $count % 2 )                      ? 'even'              : 'odd';
    		$classes[] = bbp_is_forum_category( $forum_id )        ? 'status-category'   : '';
    		$classes[] = bbp_get_forum_subforum_count( $forum_id ) ? 'bbp-has-subforums' : '';
    		$classes[] = bbp_get_forum_parent_id( $forum_id )      ? 'bbp-parent-forum-' . bbp_get_forum_parent_id( $forum_id ) : '';
    		$classes[] = 'bbp-forum-status-'     . bbp_get_forum_status( $forum_id );
    		$classes[] = 'bbp-forum-visibility-' . bbp_get_forum_visibility( $forum_id );
    
    		// Ditch the empties
    		$classes   = array_filter( $classes );
    		$classes   = get_post_class( $classes, $forum_id );
    
    		// Filter the results
    		$classes   = apply_filters( 'bbp_get_forum_class', $classes, $forum_id );
    		$retval    = 'class="' . implode( ' ', $classes ) . '"';
    
    		return $retval;
    	}
Viewing 2 replies - 1 through 2 (of 2 total)

  • niuserre
    Participant

    @niuserre

    I’ve done it using a filter in my functions.php but I’d be interested to know why the above method doesn’t work if anyone can explain please.

    My code in case anyone needs it:

    function add_clearfix( $classes ) {
    
    	$classes[] = 'clearfix';
    
    	return $classes;
    	}
    	
    	add_filter( 'bbp_get_forum_class', 'add_clearfix' );

    John James Jacoby
    Keymaster

    @johnjamesjacoby

    You could try:

    bbp_forum_class( bbp_get_forum_id(), array( 'clearfix' ) );

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar