Miten mallia tag näyttää kuvakkeet Luokka kuvakkeet Lite

Sinulla täytyy olla vähintään v1.0.4. Kopioi ja liitä tämä koodi in your mallitiedosto (index.php, loop.php, jne.):

<?php if (function_exists('get_cat_icon_lite')) echo get_cat_icon_lite();?>

You can also give it the category id. If you want to display the icon for the category id number 3, you’d do that :

<?php echo get_cat_icon_lite(3); ?>

Brand new plugin : Category Icons Lite

I wanted it to be simple to use : no more template tags !

It’ll work with a lot of themes. Just try. If you have an issue, make sure your template has the post title preceded by the permalink and its title :

<a href="<?php the_permalink() ?>" ... title="<?php the_title(); ?>">
<?php the_title(); ?>

Or :

<a title="<?php the_title(); ?>" ... href="<?php the_permalink() ?>">
<?php the_title(); ?>

For example, it’ll not work with the nice prototype theme, because it does not use the_permalink & the_title filters (from what I’ve seen).

How to use it :

1. Upload an image as usual via the Media Menu
2. Select the category you want to assign to the image
3. Save the changes

screenshot Brand new plugin : Category Icons Lite

Category Icons Lite

That’s it !

Download it now ! Category Icons Lite

New beta version !

zip New beta version !   category-icons212beta.zip (228.3 KiB, 3,188 hits)

Changelog :

  • Bug corrected : if you had 2 categories which names were similar, you could have the same icon for each category (for example : “Network” and “PlayStation Network”) in the sidebar
  • Bug corrected : in the category page, only that category icon is displayed in front of the title if the post has more than one category
  • Bug corrected : works with multisites
  • Now if there is only one icon to display, the display priority is automatically activated
  • In the Icons management panel, you’re informed if an image is not found or not displayable
  • The put_cat_icons function (used by the widget) works with WP 3.1+
  • You can now choose to get the list from put_cat_icons to process it or to display it (default behaviour). Use this to not display the list :
    put_cat_icons(wp_list_categories('title_li=&echo=0'),'echo=false');

How to get only the icons URL

If you want to get only the icons URL, you need to copy and paste this function in your functions.php file :

function extract_caticonsurl($string,$return_always_array=FALSE) {
	$myarray = array();
	if (preg_match_all('/<img\s+.*?src=[\"\']?([^\"\' >]*)[\"\']?[^>]*>/i', $string, $matches, PREG_SET_ORDER))  {
		foreach ($matches as $match) {
			$myarray[] = $match[1];
		}
	}
	if ($return_always_array === FALSE && count($myarray) == 1 ) $myarray = array_pop($myarray);
	return $myarray;
}

And paste this code where you want to get the URL(s) :

$caticons_url = extract_caticonsurl(get_cat_icon('echo=false'));

The extract_caticonsurl function returns an array if there’re several icons, or a string (the URL) if there is only one.

How to display category icons side-by-side in a widget

From Daniels ( http://www.gameblogs.com.br/ ) :

I’ve got to make a widget that will show all category icons side-by-side, and not in a list. Here is the code :

$listing_code = '';
foreach(get_categories("orderby=count&order=DESC") as $category) {
$listing_code .=get_cat_icon("echo=false&cat=".$category->cat_ID)." ";
}
$listing_code .= '';
echo $listing_code;

Thanks for sharing, Daniels. icon smile How to display category icons side by side in a widget

Update : If you want it in a widget, then you need to create a widget. Copy & paste the following code in a file named myciwidget.php in the default WordPress theme :

<?php

class MyCIWidget extends WP_Widget{
   function MyCIWidget() {
      $widget_ops = array(
         'classname' => 'my_ci_widget', // widget id
         'description' => 'displays category icons' ); // description

      $this->WP_Widget('my_ci_widget', 'My CI Widget', $widget_ops);
   }

	function widget($args, $instance) {
	 	$listing_code = '';
		foreach(get_categories("orderby=count&order=DESC") as $category) {
			$listing_code .=get_cat_icon("echo=false&cat=".$category->cat_ID)." ";
		}
		$listing_code .= '';
		echo $listing_code;
	}

}

Then, in your functions.php file, paste this :

include_once('myciwidget.php');
register_widget('MyCIWidget');

You should be able to add the widget to your sidebar.

How to display icons for pages in the sidebar

I’ve written a function that seems to be working. I think I’m going to include it in a future version of my Category Icons plugin. So, you can have page icons the same way you have category icons in the sidebar.

The following code will add icons in front of the title page in the sidebar when you use the Pages widget. You can see that I’ve used a filter named widget_pages_args to add the filter wp_list_pages in order to parse the HTML generated by wp_list_pages. It’s because I want to display icons only in the sidebar and nowhere else.

To use that code : Continue reading

How to display category icons in the sidebar

To display the icons in the sidebar, you have 2 solutions :

1. Use the widget
Go to Appearance > Widgets and drag Category Icons Widget to the right. You can have multiple Category Icons widgets.

Image 71 How to display category icons in the sidebar

Category Icons Widget

Image 8 How to display category icons in the sidebar

Category Icons Widget Settings

2. Manually

In the sidebar.php page of your WordPress theme, you must use the put_cat_icons function .

UA:F [1.6.2_892]

How to assign an icon to a page

In a previous post , I described how to do this with the help of another plugin : Page Category Plus, but this plugin does not exist anymore, so here is another way to do that.

I’ll use the theme “ lightword ” for this how to. There is 2 parts :

1. Assign a category to a page

When you’re editing the page, go to the Custom Fields, and add : caticons_page as the key, and in the value field, enter the ID of the category to which the icon is assigned to. It’s like assigning a category to a page.

caticon How to assign an icon to a page

The icon is assigned to the category ID 4

Image 21 How to assign an icon to a page

Use the Custom Fields to display a "Page Icon"

2. Use the get_cat_icon tag to display the icon

In the page.php file, after this line : Continue reading

Category Icons is a Most Wanted Category Plugin for WordPress

This is said in the website wpbeginner , in this post :

http://www.wpbeginner.com/wp-tutorials/10-most-wanted-category-hacks-and-plugins-for-wordpress/

Pictures make a site more lively which is a given which is why blogger might want to associate pictures with their category. This plugin lets you associate a specific icon of your choice to a designated category. You can use this plugin to list categories by icon with or without names, and much more.

Category Icons is a way to vastly improve your WordPress blog

This is what John Owen said in his post in Web Media Magazine : http://www.webmediamagazine.com/webdesign/50-different-ways-to-vastly-improve-your-wordpress-blog/

Usually the sidebar is clogged up with meta data, advertisement’s and tag clouds. We sometimes miss the categories in all the mess, assigning images to your categorys is a great way to fix this and will help your visitors navigate your blog with ease.

Category Icons is a way to improve navigation in WordPress

This is what John Pratt said in his post in WPHacks : http://wphacks.com/10-ways-to-improve-navigation-in-wordpress/

Having your categories a post is assigned to listed and linked is a great way to get visitors to view everything else you have posted in that category, but sometimes (like “ad blindness) readers are blinded to post meta info. Solve that by assigning images to your categories, so that they stand out prominently! All you need is the Category Icons plugin.

And I agree. icon smile Category Icons is a way to improve navigation in WordPress

How to use Category Icons tags in a script

Sometimes, you need to use the tag get_cat_icon or/and put_cat_icons in a script. So to get the icon in a variable, it must not be displayed. The parameter to not display the category and to get it returned is : echo , and it needs to be set to false . Here are examples of how to use it. If your script is not in the Loop , you must use the cat parameter and give it a category id . Continue reading