Картинки около категорий

Подскажите пожалуйста, а есть ли возможность сделать так, чтобы в сайдбаре, там где список категорий (да-да-да, нынче модного облачка категорий у меня нет), около каждой категории красовался рисуночек?
Для примера, у меня идёт несколько категорий, таких как "BMW", "Ford" и т.д. и чтобы около каждой логотипчик компании?

плагин Category Icons
http://devcorner.georgievi.net/wp-plugins/wp-category-icons/
Сайт что-то недоступен сейчас, вот ридми и код плагина

ридми

==== Category Icons ====

Tags: images,categories
Contributors: 
Plugin URI: http://devcorner.georgievi.net/wp-plugins/wp-category-icons/
Category Icons is a plugin that makes it possible to assign icons to categories.

===== FEATURES =====

The plugin has the following features:
* User can assign or clear icons to categories through admin panel.
* Directory and URL for icons can be specified thorugh admin panel. Upload options can be used instead.
* A template tag (function) is exposed to include category icon into templates.
* Plugint installs itself, by creating a database table and setting default option values, when activated.

===== INSTALLATION =====

Copy the category_icons.php file into your wp_content/plugins directory.
Activate the plugin from Plugins admin menu. 

Once the plugin is activated it creates a "Cat Icons" panel under "Options".
This will allow you to manage category icons.

===== USAGE =====

The plugin exposes the get_cat_icon function as WordPress template tag to be used in 
WordPress templates. It takes following options, passed in WordPress template tags style:
   - fit_width - maximum width of image. -1 for do not care. Default is -1
   - fit_height - maximum height of image. -1 for do not care. Default is -1
   - exapnd - Expand image to fit the rectangle if smaller? Default "false".
   - cat - Category ID. Default is current category.
   - small - Is this a small icon? Default "false"

Examples:

This example will insert the icon associated with the current category:
    <?php get_cat_icon(); ?>
    
This example inserts icon for the category with ID '5'. The image is fitted withing rectangle 100x100.
If the image is smaller than desired, it is expanded.:
    <?php get_cat_icon('cat=5&fit_width=100&height=100&expand=true'); ?>
category_icons.php


<?php
/*
Plugin Name: Category Icons
Plugin URI: http://devcorner.georgievi.net/wp-plugins/wp-category-icons/
Description: Makes it possible to assign icons to categories.
Version: 1.0
Author: Ivan Georgiev
Author URI: http://devcorner.georgievi.net/
*/
/*  Copyright 2005  Ivan Georgiev  (email : ivan@georgievi.net)

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/
?>
<?php

/**
 * @todo While I was packaging for deployment I came upon the CategoryIcon plugin [http://wiki.wordpress.org/CategoryIcon%20Plugin] - it is a good idea to make it possible to show icons to posts. This could have an option into the admin panel or can be defined on per category basis?
 */

/******************* Initialization and Hooks *****************************/
$wpdb->ig_caticons = $table_prefix.'ig_caticons';
if (basename($_SERVER['SCRIPT_NAME']) == 'plugins.php' && isset($_GET['activate'])  && $_GET['activate'] == 'true') 
   add_action('init', 'ig_caticons_install');

add_action('admin_menu', 'ig_caticons_adminmenu');
/*------------------ Initialization and Hooks END ----------------------------*/



/**
 * WordPress Template Tag to Insert Category Icon
 * Parameters:
 *   - fit_width [-1]
 *   - fit_height [-1]
 *   - exapnd [false] - Exapnd image to fit the rectangle (fit_width, fit_height)
 *   - cat - Category ID. Default is current category.
 *   - small [false] Is this a small icon?
 */
function get_cat_icon($params="") {
    parse_str($params, $p);
    if (!isset($p['fit_width'])) $p['fit_width']=-1;
    if (!isset($p['fit_height'])) $p['fit_height']=-1;
    if (!isset($p['expand'])) $p['expand']=false;
    if (!isset($p['cat'])) $p['cat']=$GLOBALS['cat'];
    if (!isset($p['link'])) $p['link']=true;
    if (!isset($p['small'])) $p['small']=false;
    
    list($icon, $small_icon) = ig_caticons_get_icons($p['cat']);
    if ($p['small']) {
        $file = ig_caticons_path()."/$small_icon";
        $url = ig_caticons_url()."/$small_icon";
        if (!is_file($file)) {
            $file = ig_caticons_path()."/$icon";
            $url = ig_caticons_url()."/$icon";
        }
    } else {
        $file = ig_caticons_path()."/$icon";
        $url = ig_caticons_url()."/$icon";
        if (!is_file($file)) {
            $file = ig_caticons_path()."/$small_icon";
            $url = ig_caticons_url()."/$small_icon";
        }
    }
    if (file_exists($file)) {
        list($width, $height, $type, $attr) = getimagesize($file);
        list($w, $h) = ig_fit_rect($width, $height, $p['fit_width'], $p['fit_height'], $p['expand']);
        echo("<img src=\"$url\" width=\"$w\" height=\"$h\"/>");
        //
    }
}



/**
 * Install the plugin
 * @access private
 */
function ig_caticons_install() {
    global $wpdb, $table_prefix;
    
    $wpdb->query("CREATE TABLE IF NOT EXISTS `$wpdb->ig_caticons` (
`cat_id` INT NOT NULL ,
`icon` TEXT NOT NULL ,
`small_icon` TEXT NOT NULL ,
PRIMARY KEY ( `cat_id` ))");
    add_option('igcaticons_path', '');
    add_option('igcaticons_url', '');
    add_option('igcaticons_filetypes', '');
}


/**
 * Integrate into the admin menu.
 * @access private
 */
function ig_caticons_adminmenu() {
    define('IG_ADMIN_SELF', $_SERVER['PHP_SELF'].'?page='.$_REQUEST['page']);
    if (function_exists('add_options_page'))
        add_options_page(
            'Cat Icons',
            'Category Icons',
            5,
            basename(__FILE__),
            'ig_caticons_adminpanel');
}


/**
 * Handle admin panel
 * @access private
 */
function ig_caticons_adminpanel() {
?>
    <div class="wrap">
        <strong>Select:</strong> <a href="<?php echo IG_ADMIN_SELF;?>&ig_module=caticons&ig_tab=manage">Manage</a> | <a href="<?php echo IG_ADMIN_SELF;?>&ig_module=caticons&ig_tab=options">Options</a>
    </div>
<?php
    $tab = isset($_REQUEST['ig_tab']) ? $_REQUEST['ig_tab'] : '';
    switch ($tab) {
        case ('manage'):
            ig_caticons_adminmanage();
        break;
        default:
            ig_caticons_adminoptions();
        break;
    }
}

/**
 * Handle manage tab (plugin section) from the admin panel.
 * @access private
 */
function ig_caticons_adminmanage() {
    global $wpdb;
    $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';

    switch ($action) {
        case 'delete':
            $cat = $wpdb->escape($_REQUEST['cat_ID']);
            $wpdb->query("DELETE FROM $wpdb->ig_caticons WHERE cat_id='$cat'");
        break;
        case 'do_select':
            $cat = $wpdb->escape($_REQUEST['cat_ID']);
            $icon = $wpdb->escape($_REQUEST['ig_icon']);
            $small_icon = $wpdb->escape($_REQUEST['ig_small_icon']);
            if ($wpdb->get_var("SELECT cat_id FROM $wpdb->ig_caticons WHERE cat_id='$cat'")) {
                $wpdb->query("UPDATE $wpdb->ig_caticons SET icon='$icon', small_icon='$small_icon' WHERE cat_id='$cat'");
            } else {
                $wpdb->query("INSERT INTO $wpdb->ig_caticons (cat_id, icon, small_icon) VALUES ('$cat', '$icon', '$small_icon')");
            }
        break;
    }


    switch ($action) :
        // List categories
    case 'select':
        $cat = $wpdb->escape($_REQUEST['cat_ID']);
        $c = $wpdb->get_row("SELECT * FROM $wpdb->categories WHERE cat_ID=$cat");
        list($icon, $small_icon) = ig_caticons_get_icons($c->cat_ID);
?>
<div class="wrap">
<h2><?php _e('Select Category Icons') ?> </h2>
<form method="post" action="">
    <input type="hidden" name="ig_module" value="caticons" />
    <input type="hidden" name="ig_tab" value="manage" />
    <input type="hidden" name="action" value="do_select" />
<table cellspacing="1" cellpadding="2" border="0">
    <tr>
        <th scope="row" align="right" valign="top">Category ID:</th>
        <td><?php echo $c->cat_ID;?></td>
    </tr>
    <tr>
        <th scope="row" align="right" valign="top">Name:</th>
        <td><?php echo $c->cat_name;?></td>
    </tr>
    <tr>
        <th scope="row" align="right" valign="top">Icon:</th>
        <td valign="top">
            <select name="ig_icon" rows="10" onChange="icon_preview.src=('<?php echo ig_caticons_url();?>/'+this.options[this.selectedIndex].value);">
                <option value="">--- No Icon ---</option>
                <?php ig_caticons_iconoptions($icon); ?>
            </select>
        </td>
        <td valign="top"><img id="icon_preview" src="<?php echo ig_caticons_url()."/$icon";?>" /></td>
    </tr>
    <tr>
        <th scope="row" align="right" valign="top">Small Icon:</th>
        <td valign="top">
            <select name="ig_small_icon" rows="10" onChange="small_icon_preview.src=('<?php echo ig_caticons_url();?>/'+this.options[this.selectedIndex].value);">
                <option value="">--- No Icon ---</option>
                <?php ig_caticons_iconoptions($small_icon); ?>
            </select>
        </td>
        <td valign="top"><img id="small_icon_preview" src="<?php echo ig_caticons_url()."/$small_icon";?>" /></td>
    </tr>
</table>
    <div class="submit"><input type="submit" name="info_update" value="Select Icons &raquo;" /></div>    
</div>
<?php
    break;
    
    default:
?>
<div class="wrap">
<h2><?php _e('Manage Categories') ?> </h2>
<table width="100%" cellpadding="3" cellspacing="3">
    <tr>
        <th scope="col"><?php _e('ID') ?></th>
        <th scope="col"><?php _e('Name') ?></th>
        <th scope="col"><?php _e('Icon') ?></th>
        <th scope="col"><?php _e('Small Icon') ?></th>
        <th colspan="2"><?php _e('Action') ?></th>
    </tr>
<?php
ig_caticons_rows();
?>
</table>

</div>
<?php
    endswitch;
}


/**
 * Handle options tab (plugin section) from the admin panel.
 * @access private
 */
function ig_caticons_adminoptions() {
    if (isset($_POST['info_update'])) {
        ?><div class="updated"><p><strong>Settings updated.</strong></p></div><?php
        update_option('igcaticons_path', $_POST['igcaticons_path']);
        update_option('igcaticons_url', $_POST['igcaticons_url']);
        update_option('igcaticons_filetypes', $_POST['igcaticons_filetypes']);
    }
?>
<div class=wrap>
  <form method="post" action="">
    <input type="hidden" name="ig_module" value="caticons">
    <input type="hidden" name="ig_tab" value="options">
    <h2>Category Icons Settings</h2>
     <fieldset name="set1">
        <legend>General Settings</legend>
        <table cellspacing="0" cellpadding="2" border="0">
            <tr>
                <th align="right" valign="top">Local Path to Icons:</th>
                <td><input type="text" name="igcaticons_path" size="50" value="<?php echo htmlspecialchars(get_option('igcaticons_path')); ?>" /><br />Leave blank to use settings file upload path (<?php echo htmlspecialchars(get_option('fileupload_realpath')); ?>).</td>
            </tr>
            <tr>
                <th align="right" valign="top">URL to Icons:</th>
                <td><input type="text" name="igcaticons_url" size="50" value="<?php echo htmlspecialchars(get_option('igcaticons_url')); ?>" /><br />Leave blank to use settings file upload url (<?php echo htmlspecialchars(get_option('fileupload_url')); ?>).</td>
            </tr>
            <tr>
                <th align="right" valign="top">Image File Types:</th>
                <td><input type="text" name="igcaticons_filetypes" size="50" value="<?php echo htmlspecialchars(get_option('igcaticons_filetypes')); ?>" /><br />Leave blank to use settings file upload filetypes (<?php echo htmlspecialchars(get_option('fileupload_allowedtypes')); ?>). Separate by space or comma.</td>
            </tr>
        </table>
     </fieldset>
    <div class="submit"><input type="submit" name="info_update" value="Update Options &raquo;" /></div>    
  </form>
</div>
<?
}


/**
 * Get the icons base path.
 */
function ig_caticons_path() {
    $path = get_option('igcaticons_path');
    if (''==$path)
        return get_option('fileupload_realpath');
    else
        return $path;
}

/**
 * Get the icons base url.
 */
function ig_caticons_url() {
    $url = get_option('igcaticons_url');
    if (''==$url)
        return get_option('fileupload_url');
    else
        return $url;
}

/**
 * Get file types to show when selecting icons.
 */
function ig_caticons_filetypes() {
    $types = get_option('igcaticons_filetypes');
    if (''==$types)
        return get_option('fileupload_allowedtypes');
    else
        return $types;
}


/**
 * Print list of options for selecting icon.
 * @access private
 */
function ig_caticons_iconoptions($selected='') {
    $path = ig_caticons_path();
    $d = dir($path);
    $ext = explode(' ', strtolower(ig_caticons_filetypes()));
    while (false !== ($entry = $d->read())) {
        if (is_dir($path.DIRECTORY_SEPARATOR.$entry)) continue;
        $p = strrpos($entry,'.');
        if (false===$p || !in_array(strtolower(substr($entry, $p+1)), $ext)) continue;
        $sel = ($selected==$entry) ? ' selected="selected"' : '';
        $entry_escaped = htmlspecialchars($entry);
        echo("<option value=\"$entry_escaped\"$sel>$entry_escaped</option>");
    }
    $d->close();    
}

/**
 * Get category icons.
 * @param int $cat Category ID
 * @return array (icon, small_icon)
 */
function ig_caticons_get_icons($cat) {
    global $wpdb;
    $cat = $wpdb->escape($cat);
    if ($row = $wpdb->get_row("SELECT icon, small_icon FROM $wpdb->ig_caticons WHERE cat_id='$cat'")) {
        return array($row->icon, $row->small_icon);
    } else return false;
}


/**
 * Utility function to compute a rectangle to fit a given rectangle by maintaining the aspect ratio.
 */
function ig_fit_rect($width, $height, $max_width=-1, $max_height=-1, $expand=false) {
    $h = $height;
    $w = $width;
    if ($max_width>0 && ($w > $max_width || $expand)) {
        $w = $max_width;
        $h = floor(($w*$height)/$width);
    }
    if ($max_height>0 && $h >$max_height) {
        $h = $max_height;
        $w = floor(($h*$width)/$height);
    }
    return array($w,$h);
}


/**
 * Print category rows for admin panel
 */
function ig_caticons_rows($parent = 0, $level = 0, $categories = 0) {
    global $wpdb, $class, $user_level;
    if (!$categories)
        $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name");

    if ($categories) {
        foreach ($categories as $category) {
            if ($category->category_parent == $parent) {
                list($icon, $small_icon) = ig_caticons_get_icons($category->cat_ID);
                $icon_cell = '';
                if (''!=$icon) {
                    list($width, $height, $type, $attr) = getimagesize(ig_caticons_path()."/$icon");
                    list($w, $h) = ig_fit_rect($width, $height, 100, 100);
                    $icon_cell = '<img src="'.ig_caticons_url()."/$icon\" width=\"$w\" height=\"$h\"/> <br />$icon ($width x $height)";
                }
                $small_icon_cell = '';
                if (''!=$small_icon) {
                    list($width, $height, $type, $attr) = getimagesize(ig_caticons_path()."/$small_icon");
                    list($w, $h) = ig_fit_rect($width, $height, 100, 100);
                    $small_icon_cell = '<img src="'.ig_caticons_url()."/$small_icon\" width=\"$w\" height=\"$h\" /> <br />$small_icon ($width x $height)";
                }
                $category->cat_name = wp_specialchars($category->cat_name);
                $count = $wpdb->get_var("SELECT COUNT(post_id) FROM $wpdb->post2cat WHERE category_id = $category->cat_ID");
                $pad = str_repeat('— ', $level);
                if ( $user_level > 3 )
                    $edit = "<a href='".IG_ADMIN_SELF."&ig_module=caticons&ig_tab=manage&action=select&cat_ID=$category->cat_ID' class='edit'>" . __('Select') . "</a></td><td><a href='".IG_ADMIN_SELF."&ig_module=caticons&ig_tab=manage&action=change&cat_ID=$category->cat_ID' onclick=\"return confirm('".  sprintf(__("You are about to remove the category \'%s\' icons.\\n  \'OK\' to remove, \'Cancel\' to stop."), addslashes($category->cat_name)) . "')\" class='delete'>" .  __('Remove') . "</a>";
                else
                    $edit = '';
                
                $class = ('alternate' == $class) ? '' : 'alternate';
                echo "<tr class='$class'><th scope='row'>$category->cat_ID</th><td>$pad $category->cat_name</td>
                <td align=\"center\">$icon_cell</td>
                <td align=\"center\">$small_icon_cell</td>
                <td>$edit</td>
                </tr>";
                ig_caticons_rows($category->cat_ID, $level + 1, $categories);
            }
        }
    } else {
        return false;
    }
}

?>

Спасибо огромное, sonika!
Я как раз искал какой-нибудь плагин, но почему-то ничего достойного не находил.
Единственное, я ещё до конца не понял, как им правильно пользоваться, не было времени разобраться 🙁
Установить – установил, в опциях он появился, я даже могу выбрать, из каких папок и с каким расширением ему подцеплять файлы, но сделать привязку конкретной картинки к конкретной категории пока что ещё не получилось.

А Вы поищите в англоязычной части интернета, может на форумах http://wordpress.org/support/ обсуждали этот плагин.
Я сама его не ставила.

Выяснил, что если на 2.0.4 плагин работает, то на 2.1 (на который мне, собственно, и надо поставить Category Icons) возможности привязать категорию к картинке нет 🙁 А ещё и разработчик вместе с сайтом куда-то пропал, незадача!

а еще бы не помешала иконка в названии поста %)

http://guff.szub.net/2006/02/09/post-image/

Вы святые

Anonymous
Отправить
Ответ на: