Jump to content

Getting an image to display if a field = something


bigbrennan

Recommended Posts

Hi guys, stumbled across the site whilst looking for help!

 

I am using wordpress blog, and have used the following to get the latest blog title + category to display:

 

Head - <?php require('blog/wp-blog-header.php');?>

 

Body -

<?php if (have_posts()) : ?>

                <?php while (have_posts()) : the_post(); ?>

                <div class="post" id="post-<?php the_ID(); ?>">

                  <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">

                    <?php the_title(); ?>

                  </a></h2>

                  <small>

                    <!-- by <?php the_author() ?> -->

                  </small>

                  <p class="postmetadata">

                    <?php the_category(', ')?>

                  </p>

                </div>

                <?php endwhile; ?>

                <div class="navigation">

                  <div class="alignleft">

                    <?php next_posts_link('« Previous Entries') ?>

                  </div>

                  <div class="alignright">

                    <?php previous_posts_link('Next Entries »') ?>

                  </div>

                </div>

                <?php else : ?>

                <h2 class="center">Not Found</h2>

                <p class="center">Sorry, but you are looking for something that isn't here.</p>

                <?php include (TEMPLATEPATH . "/searchform.php"); ?>

                <?php endif; ?>

 

 

 

Now what I want to happen is it to display an image dependent on what category it is.

 

I tried this:

 

<?php

    if($var_the_category=="Uncategorized"){

      echo "<img src=\"images\top2.jpg" alt=\"\" />";

    }

    elseif($var_the_category=="name2"){

      echo "<img src=\"image2.jpg\" alt=\"\" />";

    }

    elseif($var_the_category=="name3"){

      echo "<img src=\"image3.jpg\" alt=\"\" />";

    }

?>

 

But something is not working.... could some care to explain where I have gone wrong?

 

Thanks  ;D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.