Forums

[resolved] HELP - category postes (11 posts)

  1. taghaboy
    Member
    Posted 2 years ago #

    Hi,
    i play with the Template Tags/is_category to show the banner img to each category post, and it work perfectly:

    <?php if (is_category()) { ?>
    <img src="<?php foreach((get_the_category()) as $category) { echo get_bloginfo ( 'stylesheet_directory' ) . '/cat-banner/' . $category->category_nicename . '.jpg" alt="' . $category->cat_name . '" />'; } ?>
    </img>

    but this code dont show any thing when i browse a page inside any category!!!
    what's the solution pls, and sorry for my english.
    Thanks

  2. taghaboy
    Member
    Posted 2 years ago #

    hello :)

  3. esmi
    Theme Diva & Mod
    Posted 2 years ago #

    What's the </img> at the end for?

    is_category tests to see if the current page is a category page. As soon as you select a post, the current page is no longer a category page, so - no image.

  4. taghaboy
    Member
    Posted 2 years ago #

    thanks for the comment, so there is no way to know if the post are in a category x?

  5. fanalejr
    Member
    Posted 2 years ago #

    Hey man,
    Check out the in_category(); template tag, thats what your looking for... its an if statement that says if the post is in "this" category, do this

    Codex page is here

  6. taghaboy
    Member
    Posted 2 years ago #

    Hi fanalejr,
    thanks for your reply, i use it and it work, but i must add all the time the cat names every time i'add the new one as:

    <?php if ( in_category( array( 'fruits', 'apples', 'bananas', 'cantaloupes', 'guavas', /*etc*/ ) ) {
    	// These are all fruits
    }
    ?>

    So i'd like if the Template Tags/in_category to be dynamic and know all the category i add or the costumer add, like in :
    <?php if (is_category()) { ?>
    and the question is : how can i let the in_category to be global.
    Thanks a lot

  7. taghaboy
    Member
    Posted 2 years ago #

    hi, i have the code, but it dont let other code to work:
    (!in_category('$il_asides_cat')

    i have set a banner image to be in the header of search page :

    <?php } elseif (is_search() ) { ?>
    <img src="<?php bloginfo('stylesheet_directory'); ?>/cat-banner/recherche.jpg"></img>
    <?php } ?>

    but in place to see the search banner (recherche.jpg), it appear the banner of first result!!!

    so please what's the solution?
    and what does mean "!" and "$il_asides_cat"?
    Thanks

  8. taghaboy
    Member
    Posted 2 years ago #

    also this do the some thing

    <?php if ( in_category('category_id') ): ?>
    <?php endif; ?>
  9. taghaboy
    Member
    Posted 2 years ago #

    Woooow finally, thanks to alanft:
    http://wordpress.org/support/topic/235961?replies=5

    this is the code:

    <?php } elseif (is_single() &amp;&amp; !in_category(category_id) ) { ?>
    /content her
    <?php } ?>

    dont remove the "!" i dont know what is it's role, but the code now work in all the page and post, and other conditional tags work as a charm :p
    (alhamdo lilah)

  10. esmi
    Theme Diva & Mod
    Posted 2 years ago #

    ! is PHP for "not" so:

    is_single() && !in_category(category_id)

    translates to:

    If this is a single post AND is NOT in the category...

  11. taghaboy
    Member
    Posted 2 years ago #

    Hi esmi, your angel
    thanks for information

Topic Closed

This topic has been closed to new replies.

About this Topic