Forums

Different banners for different categories (8 posts)

  1. Situation
    Member
    Posted 5 years ago #

    Hello.

    I am tryin' to show a different banner on every category page, instead of the boring <h2> that is default on archive.php file.

    So I created a banner for every category, and named it after the category's title; for example, category "Pizza" has a banner called pizza.gif, and category "Chinese Food" has a banner called chinese-food.gif.

    After that, I put this code on my archive.php file (where blahblahblah is my URL), 'cause I didn't want to write an is_category conditional for EVERY category:
    <img src="http://blahblahblah/<?php single_cat_title (); ?>.gif">

    Now, when I open the various categories on my browser, I can only see the banners whose filename is a one-word one. Not the others.

    So, to avoid the problem, I thought I could rename the banners with the category's ID, and change the php code into my <img> tag, but I found that the tag the_category_ID is not active anymore....

    What can I do?

  2. Situation
    Member
    Posted 5 years ago #

    Anyone?

  3. dbasulto
    Member
    Posted 5 years ago #

    you can try with `<?php category_nicename() ?>
    `
    i think that hook converts "Categories With Spaces" to categories-with-spaces

    or you can try:

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

  4. Chris_K
    Member
    Posted 5 years ago #

    Check out Category_Templates?

  5. halfbloodprince
    Member
    Posted 5 years ago #

    According to the Codex,

    <?php the_category_ID(); ?> has been replaced by

    <?php
    foreach((get_the_category()) as $category) {
        echo $category->cat_ID . ' ';
    } ?>

    So you could try doing it this way:

    <img src="<?php
    foreach((get_the_category()) as $category) {
        echo $category->cat_ID . ' ';
    } ?>.gif" alt="" />
  6. Situation
    Member
    Posted 5 years ago #

    @dbasulto:

    I tried with

    <?php category_nicename() ?>

    but got nothing, and with the code written into the link you suggested me, but the result is that I see banners for ALL categories associated with the posts.

    So, if I go to www.example.com/category/pizza, I want to get only the pizza.gif banner, not the other categories, too.

  7. Situation
    Member
    Posted 5 years ago #

    anyone else?

  8. Jon Griffith
    Member
    Posted 4 years ago #

    So the concept is to set a variable that holds the value from the category and then use it wherever...right?

    the_category_ID was displaying on the page and I couldn't figure out how to hide the category number while also using the_category_ID in a conditional statement.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.