This is a plugin for the best blogging engine b2evolution. It inserts a topic icon related to your post’s main category.
INSTALL:
- Edit variables in function topic_icon
- Upload to your plugins/renderers directory
Of note: I’ve replaced spaces in category names with _ so that a topic icon for category: Main Category looks for an image called $imageprefix.”Main_Category”.$imagetype.
Download: HERE.
CODE:
< ?php
/*
Plugin Name: Topic Icon
Version: 0.1
--------------- b2evolution plugin -----------------------
Plugin URI: http://brotherson.com/index.php/2004/12/11/topic_icon_for_b2evolution
Author: Matt Brotherson
Email: mattbta@gmail.com
---------------- original wordpress plugin -----------------------
Plugin URI: http://www.trommetter.com/cgi-bin/view.cgi/Main/WPTopicIcon
Author: Jason A. Trommetter
Email: jason@trommetter.org
---------------------------------------------------------------------------
INSTALL: Copy to your plugins/renderers folder.
Edit the variables in function topic_icon()
*/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
/**
* Includes:
*/
require_once dirname(__FILE__).'/../renderer.class.php';
/**
* @package plugins
*/
class thumbicon_Rendererplugin extends RendererPlugin
{
var $code = 'b2evtopicon';
var $name = 'Topicon';
var $priority = 75;
var $apply_when = 'opt-out';
var $apply_to_html = true;
var $apply_to_xml = false; // strip the BBcode
var $short_desc = 'inserts a topic icon for posts';
var $long_desc = 'Based on your post\'s category, this plugin will insert an icon.';
/**
* Constructor
*
* {@internal cpg_Rendererplugin::cpg_Rendererplugin(-)}}
*/
function cpg_Rendererplugin()
{
$this->short_desc = T_('inserts a topic icon for posts');
$this->long_desc = T_('Based on your post\'s category, this plugin will insert an icon.');
}
function render( & $content, $format )
{
if( ! parent::render( $content, $format ) )
{ // We cannot render the required format
return false;
}
$content = topic_icon( $content);
return true;
}
}
function topic_icon ($text)
{
global $Item, $DB;
$topic_uri = "http://www.yoursite.com/path/to/topicicons/"; //URI to your topic icon images
$topic_dir = "/filepath/to/topicicons/"; //filepath to your topic icon images
$align = "left"; //image align tag
$prefix = "topic"; //image prefix
$filetype = ".gif"; //image filetype
$topiconclass = "topicon_"; //CSS class for topic icon
//initialize variable
$content = '';
//get main category for post
$categories = $Item->main_cat_ID;
//get the category name
$sql = "SELECT cat_name from evo_categories WHERE cat_ID = $categories";
$results = $DB->get_results($sql);
if ($results) {
foreach ($results as $result) {
$category_name = $result->cat_name;
$linktitle = $category_name;
$category_name = str_replace(" ", "_", $category_name);
$filename = $topic_dir . $prefix .
strtolower($category_name) . $filetype;
if (file_exists($filename))
{
$imagename = $topic_uri . $prefix .
strtolower($category_name) . $filetype;
}
}
}
//create image tag
if ($imagename) {
list($width, $height, $type, $attr) =
getimagesize($filename);
$content .= "<img xsrc='" . $imagename . "'";
$content .= " align='" . $align . "'";
$content .= " width='" . $width . "'";
$content .= " height='" . $height . "'";
$content .= " class='" . $topiconclass . "'";
$content .= " alt='" .$linktitle . "'";
$content .= " title='" .$linktitle . "'";
$content .= "' />\n";
} else {
$content = "<!--no icon-->";
}
//append image tag to the beginning of post content
$text = $content . $text;
return $text;
}
//Register the plugin:
$this->register( new cpg_Rendererplugin() );
?>


Any chance you’re working towards a version that will snag topicons for subcategories? It’s a great plugin, especially since it uses getimagesize correctly, but for me subcats would be a hookup.
By the way, I just cloned an avatar plugin based on this. Will publish once a few kinks are worked out.
The only way i can foresee this working is if your categories are created in order, IE this post is in categories tech –> code –> b2evolution and I created category tech before code before b2evolution.
If that’s the case, replace the $sql variable with this:
Where can get nice icons?
Thanks,
I install the plug in but it does not appear in the backoffic “setting/plugin” list.
how does it pick an icon? Do I have to get or make my own icons and how I assign an icon to a caregory?
Thanks for your help.