bbpress topic info short code

This short code will show the current topic info of the bbpress forum plugin on the sidebar. You can place this code on your theme functions.php file.

 

/**
 * bbpress topic info short code
 */
function bbpress_topic_info_func( $atts ){

    global $wp_query;
    $post = $wp_query->get_queried_object();

    if($post->post_type == "topic"){ 

      ob_start();

     ?> 

   <ul class="topic-info">
      <li class="topic-forum">
          In:<?php echo get_the_title($post->post_parent);?>
      </li>
      <li class="reply-count">
          <?php echo bbp_get_topic_post_count($post->ID, false);?> Replies
      </li>
      <li class="voice-count">
          <?php echo bbp_get_topic_voice_count($post->ID, false); ?> Participants
      </li>
      <li class="topic-freshness-author">
          Last Activity <?php echo bbp_get_topic_last_active_time($post->ID, false); ?>
      </li>
      <li class="topic-subscription-link"><?php bbp_topic_subscription_link(); ?></li>
      <li class="topic-favorites-link"><?php bbp_user_favorites_link(); ?></li>
  </ul>     

  <?php
  return ob_get_clean();

    }

}
add_shortcode( 'bbpress-topic-info', 'bbpress_topic_info_func' );

/**
 * bbpress subscription link | hide
 * From https://bbpress.org/forums/topic/is-there-a-way-to-remove-this-character-next-to-the-subscription-link/
 */

function hide_before ($args = array() ) {
$args['before'] = '';
return $args;
}
add_filter ('bbp_before_get_forum_subscribe_link_parse_args','hide_before') ;

You can use this short code like this [bbpress-topic-info]

 

4 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply