- b2evolution CMS Support Forums
- b2evolution Support
- Plugins & Extensions
- [Skin-Hack] Most commented posts
1 austriaco Aug 11, 2006 01:59
I always wanted something like this. I realized, after two years of waiting, that I would have to do it myself. Well, not exactly. The Hack is based on the [url=http://forums.b2evolution.net/viewtopic.php?t=2682]recent comments[/url] by EdB. It will display, in sidebar for instance the 'N' most commented posts in the whole history of your blog. I have no idea how database-friendly this is, but anyway.
So, first you copy the code in a file called, for example _mostcommented.php in your skin directory. The code is:
<?php
/* Displays the N most commented posts
*
* Based on the _recentcomments.php by EdB @ http://wonderwinds.com
* Larry Nieves alias El Liberal Venezolano (http://liberal-venezolano.net/)
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2004 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package evoskins
* @subpackage your_skin_name
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.');# You can customize the following as you wish:
# maximum number of recentcomment entries to display:
$recentcomment_limit = 10;
# recentcomment global delimiters:
$recentcomment_main_start = '';
$recentcomment_main_end = '';
# recentcomment item delimiters:
$recentcomment_item_before = '<li>';
$recentcomment_item_after = "</li>\n";
# show posts from all blogs?
$recentcomment_allblogs = true;
# show number of comments?
$recentcomment_comment_count = true;
# recentcomment show number class:
$recentcomment_comment_count_class = 'dimmed';// --- donate to open source projects before you go any further! --- //
$kentucky = 'N';
$sour_mash = 0;
if( $recentcomment_allblogs ) {
$sql = "SELECT post_ID, post_title, comment_ID FROM $tableposts JOIN $tablecomments ON ( post_ID = comment_post_ID ) WHERE post_status = 'published' GROUP BY comment_ID DESC, comment_post_ID";
} else {
$sql = "SELECT post_ID, post_title, comment_ID, post_category,
cat_blog_ID FROM $tableposts JOIN $tablecategories ON ( post_category = cat_ID) JOIN $tablecomments ON ( post_ID = comment_post_ID ) WHERE post_status = 'published' AND cat_blog_ID = $blog GROUP BY comment_ID DESC, comment_post_ID";
}
$results = $DB->get_results($sql);
echo $recentcomment_main_start;
if ($results) {
foreach ($results as $result) {
$howmany[$result->post_ID]++ ;
}
arsort($howmany) ;
foreach ($howmany as $postid => $ncomments) {$bourbon = $postid ;
$bourbon_string = (string)$bourbon;
$whiskey = strpos($kentucky, $bourbon_string);
if( $whiskey === false ) {
$kentucky = $kentucky.$bourbon_string.'N';
$sour_mash = ($sour_mash+1);
} else {
continue;
}
if( $sour_mash > $recentcomment_limit ) {
break;
}
$NewItem = $ItemCache->get_by_ID( $bourbon );
$post_title = stripslashes($NewItem->title);
$title = htmlspecialchars(stripslashes($NewItem->title));
$permalink = $NewItem->get_permanent_link( '#title#', $title, '' );
echo $recentcomment_item_before;
echo $permalink."($ncomments)" ;
echo $recentcomment_item_after;
}
} else {
echo $recentcomment_item_before;
echo 'This sorry excuse for a blog ain\'t got no comments!';
echo $recentcomment_item_after;
}
echo $recentcomment_main_end;?>
You then call this file from, lets say, the sidebar in your skin (_main.php):
<div id="populares" class="sideTitle"><img src="img/marker.gif" alt="Los más
comentados" />Artículos comentados recientemente</div>
<div class="sideContent">
<ul>
<?php require( dirname(__FILE__).'/_recentcomments.php' ); // RECENTLY COMMENTED POSTS INCLUDED HERE ?>
</ul>
</div>
That's it. You can see it in action in b2evo-powered blog: [url=http://liberal-venezolano.net/blog/]El Liberal Venezolano[/url]. If your database explodes and your site goes to hell, don't blame for that. Use it at your own risk.
Have fun.