Forum Replies Created

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter tranceplant

    (@tranceplant)

    ^Hey jay

    that code was exactly what I was looking for. I feel i’m learning a bit here…. But yeah I wish I knew PHP like you guys.

    <?php
    foreach((get_the_category()) as $category) {
    if ( $category->cat_name == ‘FOOTBALL’ ) {
    echo “hello world”;
    }
    }
    ?>

    Thanks again for your time and understanding. Your explaination was very good.

    I’ll leave you guys alone now ??

    Thread Starter tranceplant

    (@tranceplant)

    oh thanks. I see what you did here. It does work.

    but in both cases HELLO WORLD would appear.

    What I was looking for is basically to have HELLO WORLD in all the posts that ‘contains’ FOOTBALL. So SOCCER alone wouldn’t have the HELLO WORLD.

    Thanks for your patience and time!

    Thread Starter tranceplant

    (@tranceplant)

    oh yea, that did the trick. The only thing I was missing was the apostrophe.

    Thanks a million.

    I found what I was looking for and it’s perfect like that, but I’ll push my luck a little further.

    I just realize that if I have 2 categories selected it wouldn’t work. Not a big deal, but would it be easy to have it say. if the name category is simply one of the many selected. Meaning, if I have football and hockey selected as a category the HELLO WORLD would still work.

    Ok if it’s easy to do that would be great, if not, it will be all good.

    Thanks again guys ??

    Thread Starter tranceplant

    (@tranceplant)

    Thanks for your help guys, I appreciate it.

    Like I said I am not a pro with PHP, to be honest I played around with this code and it worked, so my method is not exactly out of the book.

    What I am looking to do here is when the user clicks a category that is named “football” for example. I want to write “hello world”

    So let me write it the way I see it

    <?php
    $category = get_the_category();
    if ( $category[0]->cat_name == FOOTBALL )
    {
    echo “hello world”;
    }
    ?>

    ^I know this is wrong, but when a user creates a post, he simply needs to click the category FOOTBALL and the HELLO WORLD would show on the index page when reading.

    I hope that make sense.

    cheers

    Thread Starter tranceplant

    (@tranceplant)

    HUmm, seriously I am not sure I understand the content of the link. Like I said I am a beginner.

    I am not looking to echo the category name, I just want to use it in a “if” statement.

    you know you should post the solution when you figure it out. Please

Viewing 6 replies - 1 through 6 (of 6 total)