Page 1 of 1

add an thumbnail icon next to each Categories ?

Posted: Sun Dec 05, 2004 10:25 pm
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
.......
...
.

Re: add an thumbnail icon next to each Categories ?

Posted: Sun Dec 05, 2004 11:03 pm
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.

Posted: Mon Dec 06, 2004 8:42 am
by dkny70007
hi there, i have no knowladge about php, so could you help me out..thank you.

Posted: Mon Dec 06, 2004 2:18 pm
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;
    }

}
?>

Posted: Sun Mar 11, 2007 3:39 pm
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.

Posted: Sun Mar 11, 2007 4:37 pm
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