WordPress.org

Ready to get started?Download WordPress

Forums

Post Content And Template Tags Determined By Category? (3 posts)

  1. mookboy
    Member
    Posted 9 years ago #

    Hi, I'm completely new to WP and PHP and I'm getting a late night head ache trying to figure out the following brain teaser. Any help would be greatly appreciated!

    I am using the excerpt field for a user uploaded image file name. This file name will then be added like this: <img src="http://www.domain.co.uk/word/cdimages/<?php the_excerpt(); ?>"> . This allows me to add the cover of an album to a review post, with each new post refering to an image in the above folder to accompany the review body.

    However!

    I only want to do this on posts that are in my Reviews catergory. Otherwise, when I check (for instance) my news posts, I get the tiny icon to tell me that an image file name does not exist (as it's only entered for reviews and for every other category its left blank).

    So. Is it possible to somehow specify on a category basis, if the excerpt (or other optional content) should be added or not?

    Also, is it still possible for me to use the default 120 word excertp ASWELL or is that just impossible?

  2. Lorelle
    Member
    Posted 9 years ago #

    1. You can use the default 120 word excerpt by replacing the_content() tag with the_excerpt(). See:
    http://codex.wordpress.org/Customizing_the_Read_More

    2. Check the Conditional Tags for is_category() here:
    http://codex.wordpress.org/Conditional_Tags

  3. mookboy
    Member
    Posted 9 years ago #

    [NOTE: I've opted for custom fields to hold the URL for the CD cover, instead of the excerpt field.]

    I've tried the conditional tags, but I can't seem to get them to work. I've added the following:

    <?php if (is_category('3'))
    {
    echo "image file";
    }
    else
    {
    echo "";
    }
    ?>

    So that if category 3 is being displayed, it shows the image and if its anything else, it replaces that with a blank space. However it only ever puts in the space (I changed it to a word to check) and it appears to ignore the category number.

    Any idea whats going wrong here?

    Lastly, I need for an image file to appear (not the words!) when true, however if I add:

    "<img src="http://www.vendettazine.co.uk/w/cdimages/<?php echo $post->post_customfieldone; ?>" class="alignleft">"

    It comes up with a parse error. I really am stumped.

    Apologies for the newbie-ness of this...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.