As you know, there is a plugin named "bbPress New Topics." However, it seems it does not work with the latest version of WordPress. I installed it and tried to make it worked, but in vain.
I decided to make this feature for myself. I implemented it by comparing two dates: the current date and the topic date. If the date difference is less than 3 days for example, the label "New" is added.
You can test it on this forum.
To add this feature, you need to add a few lines of codes to loop-single-topic.php (of the bbPress plugin) and functions.php (of your theme):
Please add the following function to your theme function file:
function mycustom_new_label_bbp($now, $last_active) { $now = new DateTime($new); $last_active = new dateTime($last_active); $interval = $last_active->diff($now); $difference = $interval->format('%R%a days'); if($difference < 3) { echo "<span class='mycustom_new_label'>"; echo "New"; echo '</span>'; } }
Please add the following php code to the file "loop-single-topic.php" just before the post tile code (for example, "<?php do_action( 'bbp_theme_before_topic_title' ); ?>".)
<!-- For outputting "New" label --> <?php $now = date("Y-m-d"); if ( !empty( $reply_id ) ) { $last_active = get_post_field( 'post_date', $reply_id ); } else { $last_active = get_post_field( 'post_date', $topic_id ); } ?> <?php mycustom_new_label_bbp($now, $last_active); ?>
Lastly, you need to adjust the appearance of the button using CSS code. Please add the following CSS code to your stylesheet file:
/* For displaying "New" Label for topics less than 3 days */ .mycustom_new_label { display: inline; padding: .2em .6em .3em; font-size: 11px; line-height: 1; color: #ffffff; background-color: #d9534f; text-align: center; white-space: nowrap; vertical-align: baseline; border-radius: .25em; }
Is there any way to make it as a plugin? I will try to search Internet to find out how to make WordPress plugins when I am free…
Hi,
where i can find "loop-single-topic.php" file?
Regards
raj
Hi raj
Thanks for your comment.
The “loop-single-topic.php” file can be found under:
../wp-content/plugins/bbpress/templates/default/bbpress
You can copy all files (or files you will modify) under the folder “…/wp-content/plugins/bbpress/templates/default/bbpress” to “…/wp-content/themes/your_theme_name/bbpress” and copy the css files under “…/wp-content/plugins/bbpress/templates/default/css” to “…/wp-content/themes/your_theme_name/css”. Then, the modified template files will not be affected even if bbpress is upgraded.
Hello, Thanks for this great plugin. I wanted a small change to this. if a user replies to a topic, then this symbol should disappear. can you help me with this?
Hi Nikhil
Thanks for your comment. I think it's easy to implement it.
I just tested and the following function works well:
bbp_get_topic_reply_count()
Please note that this function will return the number of replies + 1. (For example, if the actual number of replies is 2, bbp_get_topic_reply_count() will return 3.) Please consider this when creating a conditional php tag using this function.
Please feel free to contact me anytime if you have any questions.
I'll try it out. Thanks a lot!
Hello wordcracker!
Thank you for this code!! I found it really useful.
Can I make this code also show the "new" label on forms that have topics with new content? I really miss this function.
I would love this kind of function in my forum!
Hellovirre131,
Thanks for your comment.
I think it will be possible to show the "new" label on forums that have topices with new content.
Please add the following code to the file "loop-single-forum.php" (not "loop-single-topic.php"):
You can add the above code in front of "bbp_forum_title();".
I tested it and it works fine in my environment. I hope this will also work well in your system.
Thank you for the quick answer! I have one more question, when does the "new" label disappear from topics?
It will be displayed for 3 days (I did not count it, but it's expected to do so.)
If you want, you can change the number from the function:
(For example, if you change the number to "2", it will be displayed for 2 days.)
Thank you very much for visiting my blog. If you want to display the number of replies instead of that of posts in bbPress, please refer to http://www.thewordcracker.com/advanced-wordpress/how-to-modify-the-number-of-replies-in-bbpress/