add an thumbnail icon next to each Categories ?

Random stuff about serendipity. Discussion, Questions, Paraphernalia.
Post Reply
dkny7007
Regular
Posts: 9
Joined: Mon Sep 20, 2004 3:33 am

add an thumbnail icon next to each Categories ?

Post by dkny7007 »

Hi there,

can you add one more feature in the Categories manager, which we can upload a little icon and it will appear next to each Categories:

for example:
Categories

[XML] [flashicon] Flash
[XML] [photoshopicon] Photoshop
.......
...
.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: add an thumbnail icon next to each Categories ?

Post by garvinhicking »

The best way would be to write an own plugin instead of the bundled one which displays the categories. You could even duplicate the plugin as an external one with nearly the same content and then just add functionality by editing the HTML output section of the plugin.

I would go for just displaying a category image with the same name as the category.

This could be done with little PHP knowledge - if you can't get it to work, raise a hand and I will see what I can do :)

Regards,
Garvin.
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
dkny70007

Post by dkny70007 »

hi there, i have no knowladge about php, so could you help me out..thank you.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

dkny70007 wrote:hi there, i have no knowladge about php, so could you help me out..thank you.
Sure, here's your plugin. Copy + Paste that block of code into a file 'serendipity_plugin_imagecategory.php' and save it in the directory 'plugins/serendipity_plugin_imagecategory' of your Serendipity installation.

Then you can go to "configure plugins" and select the new Plugin 'Image Category' and add that to your plugins.

It will then display a second icon for every category for which a file exists. Let's say your Category is called "photoshop", then you must have a file called "templates/default/img/photoshop.gif" which will be displayed. Pay attention to upper/lowercase of the filename, and all characters whice are not A-Z or 0-9 need to be replaced with "_".

Code: Select all

<?php
class serendipity_plugin_imagecategory extends serendipity_plugin {
    var $title = 'Image Category';

    function introspect(&$propbag) {
        global $serendipity;

        $propbag->add('name',        'Image Category');
        $propbag->add('description', CATEGORY_PLUGIN_DESC . '(+ category images)');
        $propbag->add('stackable',     true);
        $propbag->add('author',        'Serendipity Team');
        $propbag->add('version',       '1.0');
        $propbag->add('configuration', array('authorid', 'image'));
    }

    function introspect_config_item($name, &$propbag)
    {
        global $serendipity;
        switch($name) {
            case 'authorid':
                $row_authors = serendipity_db_query("SELECT username, authorid FROM {$serendipity['dbPrefix']}authors");
                $authors     = array('all' => ALL_AUTHORS);
                if (is_array($row_authors)) {
                    foreach($row_authors as $row) {
                        $authors[$row['authorid']] = $row['username'];
                    }
                }

                $propbag->add('type',         'select');
                $propbag->add('name',         CATEGORIES_TO_FETCH);
                $propbag->add('description',  CATEGORIES_TO_FETCH_DESC);
                $propbag->add('select_values', $authors);
                $propbag->add('default',     'all');
                break;

            case 'image':
                $propbag->add('type',         'string');
                $propbag->add('name',         XML_IMAGE_TO_DISPLAY);
                $propbag->add('description',  XML_IMAGE_TO_DISPLAY_DESC);
                $propbag->add('default',     serendipity_getTemplateFile('img/xml.gif'));
                break;

            default:
                return false;
        }
        return true;
    }

    function generate_content(&$title) {
        global $serendipity;

        $which_category = $this->get_config('authorid');
        $categories = serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category);
        $title = $this->title;
        $html       = '';
        $image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif'));
        $image = (($image == "'none'" || $image == 'none') ? '' : $image);
        if (is_array($categories) && count($categories)) {
            $html .= $this->serendipity_generateCategoryList($categories, array(0), 3, 0, 0, $image);
        }

        $html .= sprintf(
            '<br /><a href="%s" title="%s">%s</a>',

            $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'],
            ALL_CATEGORIES,
            ALL_CATEGORIES
        );

        print $html;
    }

    function serendipity_generateCategoryList($cats, $select = array(0), $type = 0, $id = 0, $level = 0, $xmlImg = '') {
        global $serendipity;

        if ( !is_array($cats) || !count($cats) )
            return;

        $ret = '';
        foreach ($cats as $cat) {
            if ($cat['parentid'] == $id) {
                switch ($type) {
                    case 3:
                        $category_id = serendipity_makeFilename($cat['category_name']);
                        if (!empty($xmlImg)) {
                            $catimg = serendipity_getTemplateFile('img/' . preg_replace('@[^a-z0-9]@i', '_', $cat['category_name']) . '.gif');
                            if (!empty($catimg)) {
                                $catimg = '<img alt="xml" src="' . $catimg . '" style="vertical-align: bottom; display: inline; border: 0px" /> ';
                            }
                            $ret .= sprintf(
                              '<div style="padding-bottom: 2px;">' .
                              '<a href="%s" title="%s"><img alt="xml" src="%s" style="vertical-align: bottom; display: inline; border: 0px" /></a> %s%s' .
                              '<a href="%s" title="%s">%s</a>' .
                              '</div>',
                              $serendipity['serendipityHTTPPath'] . 'rss.php?category=' . $cat['categoryid'] . '_' . $category_id,
                              htmlspecialchars($cat['category_description']),
                              $xmlImg,
                              $catimg,
                              str_repeat(' ', $level * 3),
                              serendipity_rewriteURL(PATH_CATEGORIES . '/' . $cat['categoryid'] . '-' . $category_id, 'serendipityHTTPPath'),
                              htmlspecialchars($cat['category_description']),
                              htmlspecialchars($cat['category_name']));
                        } else {
                            $ret .= sprintf(
                              '%s<a href="%s" title="%s">%s</a><br />',
                              str_repeat(' ', $level * 3),
                              serendipity_rewriteURL(PATH_CATEGORIES . '/' . $cat['categoryid'] . '-' . $category_id, 'serendipityHTTPPath'),
                              htmlspecialchars($cat['category_description']),
                              htmlspecialchars($cat['category_name']));
                        }
                        break;
                }
                $ret .= $this->serendipity_generateCategoryList($cats, $select, $type, $cat['categoryid'], $level + 1, $xmlImg);
            }
        }
        return $ret;
    }

}
?>
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
superu
Regular
Posts: 24
Joined: Sun Jan 21, 2007 4:32 pm

Post by superu »

Kann ich das irgendwie kombinieren? Also anstatt des xml-icons mein eigenes Kategorie-Icon?

Für die anglophonen:

Is it possible to combine this? Like my own Category-Icon instead of the xml-icon?

Grüße,
U.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

Hi superu!

Yure. Look at the date of the thread above, now everything's a bit different.

Search this forum for "category icon plugin_category.tpl" and you should find some more recent examples. Just this week someone asked for it.

HTH,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply