WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] display the category parent’s assigned icon?

[Resolved] display the category parent’s assigned icon?

  • Hi,
    I’ve found somewhere a method to show a categorie’s assigned icon instead of it’s name. for that I’ve used this creative code:
    <img src="<?php the_category_ID(); ?>.gif"/>
    then I upload to my root folder a gif icon with the name of the category ID.

    Now I want to try and move one step forward, and display the category’s PARENT’s assigned image.(I thought of a code like: <img src="<?php the_category_parent_ID(); ?>.gif"/> but there’s no tag like this..

    is there a way to do that?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try something like this:

    <?php
    $the_cat = get_the_category();
    $cat_parent = $the_cat[0]->category_parent;
    if($cat_parent) :
    ?>
    <img src="<?php echo $cat_parent; ?>.gif" />
    <?php endif; ?>

    http://codex.wordpress.org/Template_Tags/get_the_category

    shhhhhwowwww! you are JENIUS!!!!! thanks!

    Hi Kafkaesqui,
    your method worked great, but now I have a new (but related) problem: in the archive page I’ve put this code:
    <?php /* If this is a category archive */ if (is_category()) { ?>
    <h2 class="pagetitle">
    <a href="<?php echo get_settings('home'); ?>/?cat=<?php the_category_ID(); ?>" rel="bookmark"><img src="<?php the_category_ID(); ?>.gif" alt="<?php single_cat_title(); ?>" title="<?php single_cat_title(); ?>" class="centered"/></a></h2>

    now the problem appears when the most recent post is belonged to a child category, then the parent category’s arcive page is titled with the icon of the child one.
    what I want to achive is that the page will show the icon of the correct category ( I guess I’ll need to use the get_the_category and then do something like $cat->ID ?) also, if a post in the archive is belonged to a child category then I want it (the post, not the page) to have the icon of the child category.
    thanks again for a great help.
    uri

    I bump therefore I live

    o.k. I tried it alone but it doesn’t work..
    I tried inserting the following code:
    <a href="<?php echo get_settings('home'); ?>/?cat=<?php
    $cat = single_cat_title(); echo $cat->cat_ID;
    ?>" rel="bookmark"><img src="<?php
    $cat = single_cat_title(); echo $cat->cat_ID.gif;
    ?>" alt="<?php single_cat_title('כל הרשימות שהופיעו במדור '); ?>" title="<?php single_cat_title('כל הרשימות שהופיעו במדור '); ?>" class="centered"/></a>

    but the title doesn’t show the page’s category’s ID’s gif icon, but instead it looks for the page’s category’s name‘s gif icon. I thought that if I write in the code: <?php
    $cat = single_cat_title(); echo $cat->cat_ID.gif;
    ?>
    it will output the ID.gif, but it seems I’m wrong somewhere.. It’d be so much easyer if there was a single_cat_ID option..

    found the solution here (if anyone here is actually interested): http://wordpress.org/support/topic/39343?replies=7#post-221853

    is it only me, or this forum became a bit of a wasteland lately?

    The search is down, probably why things are crappy. But it’s always good to post your solutions.

    Name of GIF are on table, you need retreive it and on time display image via php

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] display the category parent’s assigned icon?’ is closed to new replies.
Skip to toolbar