Support » Fixing WordPress » the_category_image not working anymore…

  • Perhaps someone with an eye for php and the latest nightlies could look at this. I used to have this script which would show an image/icon when the post belonged to one of four possible categories. But now it’s not working anymore. When I echo $categoryname; it will give a list of áll the categories, resulting in a wrong picturename, like cat1cat2cat3.gif, so showing nothing at all.

    function the_category_image() {
    $categories = get_the_category();
    foreach ($categories as $category) {
    echo $category->cat_name;
    $category->cat_name = stripslashes($category->cat_name);
    $categoryname = $category->cat_name;
    $picture = $categoryname.".gif";
    $dirname = '';
    switch($categoryname) {
    case 'groot':
    $alt = 'grotere afbeelding beschikbaar';
    case 'interactief':
    $alt = 'min of meer interactief';
    case 'geluid':
    $alt = 'geluid toegevoegd';
    case 'video':
    $alt = 'videofragment';
    if(file_exists($dirname.$picture)) {
    echo "<img src=\"".$dirname.$picture."\" alt=\"".$alt."\" title=\"".$alt."\">";
    } else {

Viewing 2 replies - 1 through 2 (of 2 total)
  • Anything that echoes a single category seems prone to breakage, but as this is in a nightly build I expect it will be fixed in the final release.

    I’m not sure I understand what you mean. This piece of code was put together by myself (stealing from here and there), so if the code is wrong it will stáy wrong.

    Strange. It worked in 1.2.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘the_category_image not working anymore…’ is closed to new replies.