Category ImageCategory Icons with Zero Bloat

Posted By: Gremlette - 22 Aug 2009 @ 9:25 PM
Category: Coding Bits

You will notice that this site utilises category icons.

Dodecahedrons for ‘Branding and ID’, a coffee cup for ‘Random’, a lightbulb for the ‘coding Bits’ category and so on.

This IS possible to do by using a WordPress plugin but like all plugins, they are made for general purpose and include features that you do not necessarily need. All plugins are usually quite extensive and harder to modify. Why use 1000 lines of code in various php files when a ridiculously small and simple bit of code will suffice.

Example: The plugin ‘category-icons’ is 724KB with 60 files in 13 folders

My method is 2 very simple files and 8KB using ‘incat’ and ‘iscat’ and does precisely what I need, and no more :)

MIND BOGGLINGLY SIMPLE!

You are creating 2 files : incat.php and iscat.php – Obviously remember to include.
Both are the same apart from one uses ‘in category’ and the other is ‘is category’
Do another ‘elseif’ for each category and make sure the categories are spelt correctly in the admin. To test – just create a post in each category as I have done on this site.

<?php
               
                if (is_category("Brands and ID"))
                {
                        $catimage = "/wp-content/themes/GNZ/images/catid.png";
                        $welcometext = "Summary: Portfolio items and posts containing an array of ideas, logos, branding across different media.";
                }
                elseif (is_category("Photos"))
                {
                        $catimage = "/wp-content/themes/GNZ/images/catphoto.png";
                        $welcometext = "Summary: General Photographs for Rose Gibson BA. Containing family, pictures for my youth, Photos of past projects, cars.";
                }
        echo "";
                ?>

All you do now is edit your theme template to call the catimage and welcometext where you want it to appear. Example: in page.php I use this:

<h3><a href="<?php the_permalink() ?>"><?php echo "<img src=’$catimage‘ class=’caticon’ style=’float:left;’>"; the_title(); ?></a></h3>
Tags: , , , ,

Last Edit: 27 Oct 2009 @ 03 12 PM

Comments are open

 

 Leave A Comment ...

You must be Logged in to Comment

XHTML:
You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

468x60-2
CHECK MY STATUSFOR HIRE! Get Details » . . . Rose Gibson Leaning over links