Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

Showing Hot Topics In the Sidebar

VIEWS: 17 PAGES: 1

How to showing hot topics of your Blog in the sidebar

More Info
									Friend, I wanted to share how to add the hot topics in your WordPress sidebar. What's hot
topics? Hot topics that I mean here is the post we ever get most responses or comments. It
does have its benefits featuring hot topics? Depending upon each of you, if you want to suggest
a long post with the most comments or not. May not all want to show the hot topics in the
sidebar. For those interested, I give an example code to be applied as a replacement plugin.


////////////////////////////////////////////////////////////////////////////////
// Most Comments
////////////////////////////////////////////////////////////////////////////////
function get_hottopics($limit = 5) {
global $wpdb, $post;
$mostcommenteds = $wpdb->get_results("SELECT $wpdb->posts.ID, post_title, post_name, post_date,
COUNT($wpdb->comments.comment_post_ID) AS 'comment_total' FROM $wpdb->posts LEFT JOIN $wpdb-
>comments ON $wpdb->posts.ID = $wpdb->comments.comment_post_ID WHERE comment_approved = '1' AND
post_date_gmt < '".gmdate("Y-m-d H:i:s")."' AND post_status = 'publish' AND post_password = '' GROUP
BY $wpdb->comments.comment_post_ID ORDER BY comment_total DESC LIMIT $limit");
foreach ($mostcommenteds as $post) {
$post_title = htmlspecialchars(stripslashes($post->post_title));
$comment_total = (int) $post->comment_total;
echo "<li><a href=\"".get_permalink()."\">$post_title</a><br /><span class=\"total-
com\">$comment_total comments received</span></li>";
}
}
////////////////////////////////////////////////////////////////////////////////
// Custom Hot Topics Widget
////////////////////////////////////////////////////////////////////////////////
function widget_mytheme_myhottopic() { ?>
<?php if(function_exists("get_hottopics")) : ?>
<div id="hot_topics" class="widget widget_hottopics">
<h4><?php _e('Hot Topics'); ?></h4>
<?php get_hottopics(); ?>
</div>
<?php endif; ?>
<?php }
if ( function_exists('register_sidebar_widget') ) register_sidebar_widget(__('Hot Topics'),
'widget_mytheme_myhottopic');



You look number 5 on the top line, replace the one you want, how many Hot Topics you want to
display.
This is for you who want to display it without a plugin. But it's been a lot of themes thathave the
functionality. After adding the above code in functions.php, in the Appearance tab widgets, there
will be a new widget with the name of Hot Topics. You can show ordisable the widget from
the widget settings in the Admin.

Source: http://reyzha.com/menampilkan-hot-topics-di-sidebar.html

								
To top