WordPress.org

Ready to get started?Download WordPress

Forums

the_category_image not working anymore... (3 posts)

  1. Jack
    Member
    Posted 9 years ago #

    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.

    <?php
    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 = 'http://www.spoenk.nl/weblog-beta/plaatjes/';
    switch($categoryname) {
    case 'groot':
    $alt = 'grotere afbeelding beschikbaar';
    break;
    case 'interactief':
    $alt = 'min of meer interactief';
    break;
    case 'geluid':
    $alt = 'geluid toegevoegd';
    break;
    case 'video':
    $alt = 'videofragment';
    break;
    }
    if(file_exists($dirname.$picture)) {
    echo "<img src=\"".$dirname.$picture."\" alt=\"".$alt."\" title=\"".$alt."\">";
    } else {
    }
    }
    }
    ?>

  2. Anonymous
    Member
    Posted 9 years ago #

    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.

  3. Jack
    Member
    Posted 9 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.