How to add a 'hot' label to bbpress topics

If you want to add a "hot" label to WordPress bbPress topics whose view count is equal or greater than 30, you can add the following code to "loop-single-topic.php."

<?php
$now = date("Y-m-d");  /* Today date */
$last_active = get_post_field( 'post_date', $topic_id ); /* The creation date of the current topic */
$now = new DateTime($new);
$last_active = new dateTime($last_active);
$interval = $last_active->diff($now);
$difference = $interval->format('%R%a days');
$difference = $difference + 1; /* The date difference plus 1 */
$hot_views_per_day = 30; /* The number of views per day which will be set as hot topics */
$total_counter = get_wpbbp_post_view( bbp_get_topic_id() ); /* View count of the current topic */
$acutal_views_per_day = $total_counter / $difference; /* View count per day */

if ($acutal_views_per_day >= $hot_views_per_day) {
     echo '<i class="fa fa-certificate" style="color: red;" title="Hot"></i>';
    }
?>

You can download an icon for the label "hot" from the IconArchive site or you can make a new one for you or add the word "Hot" instead of an image. (Please replace the part "<i class="fa fa-certificate" style="color: red;" title="Hot"></i>" with your code to include your cutom label icon. In addition, please change the number of views per day which will be set as hot topics. Please aslo modify the style of the img tag above. (If you want, you can make a function for this action like the "new" label in bbPress which is decribed in this post.)

Add Hot label to WordPress bbPress posts


Leave a Comment