• Hello!

    I’m willing to pay $10 by Paypal if you give me this simple hack!

    This should be very easy if you know the right variables, but I’ve searched, and searched, and nothing…

    The hack must work in the single page where the post is shown, because I want to print a a different phrase depending on the name of the category, at the bottom of each article.
    The code can be put on the single.php file.

    For example, if the category is called dogs, I would like to print the phrase: Dogs are the man’s best friend.
    If the category is called “giant animals”, I would like to print: Elephants and wales are examples of big animals.
    Well, the examples are dumb, but you get the picture ??

    This could even be used to print different images depending on the category name. If the post is in the category dogs, you could show an image of a dog at the bottom of each article!
    The real problem is doing that in the single page, not in the category main page :/

    So, I only need a simple case structure, linked to the right variable, that can be called on the every page of my blog.
    I can’t use functions like the_category(); because it prints a character, so the if clauses or cases don’t work.

    I use WordPress 2.0.

    Thank you!!!

    Nuno

Viewing 3 replies - 16 through 18 (of 18 total)
  • The code earlier:
    <?php foreach((get_the_category()) as $cat) { $nuno=$cat->cat_name . ' '; } if ($nuno == "cats") { echo "Hello";} ?>
    … isn’t valid because it adds on a space each time. you’d need to either compare each category as you go:
    <?php
    foreach((get_the_category()) as $cat) {
    if ($cat->cat_name=='cats') {
    echo 'hello';
    }
    }
    ?>

    The issue is if you use multiple categories per post, and what to do in those cases.

    If you want to store text in the description and just print without ‘checking’, you could do something like:
    <?php
    foreach((get_the_category()) as $cat) {
    echo '<p>'.category_description($cat->cat_ID).'<p>';
    }
    ?>

    That will print ALL category descriptions if multiple cats per post…

    -d

    Thread Starter webmaster7

    (@webmaster7)

    Hello!

    Geoffe, your code works perfectly if you are inside the category, but if you click on any entrie, the code stops working maybe because the single_cat_title function can’t recognize the category to which the single entries belong.

    David, your multiple categories problem raise some questions, but at least for that site I won’t have such problems, because each entry belongs to just one category.

    I decided to use Kafkaesqui plugin, and make a donation to him.

    Thank you all, this was really a great thread!!!

    Bye!

    Nuno

    Thread Starter webmaster7

    (@webmaster7)

    Donations made:

    $5 for SzubNet
    $5 for Matthew Mullenweg

    Even without asking, I always keep my word ??

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Need paid help! Print a phrase depending on the category name.’ is closed to new replies.