[resolved] display the category parent's assigned icon? (9 posts)

  1. uriash
    Posted 10 years ago #

    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?

  2. Kafkaesqui

    Posted 10 years ago #

    Try something like this:

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


  3. uriash
    Posted 10 years ago #

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

  4. uriash
    Posted 10 years ago #

    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.

  5. uriash
    Posted 10 years ago #

    I bump therefore I live

  6. uriash
    Posted 10 years ago #

    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..

  7. uriash
    Posted 10 years ago #

    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?

  8. maerk
    Posted 10 years ago #

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

  9. zebra
    Posted 10 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic