Title: PHP Help
Last modified: August 18, 2016

---

# PHP Help

 *  [jefft](https://wordpress.org/support/users/jefft/)
 * (@jefft)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/php-help-1-3/)
 * I dont know PHP and looked for the answer, but couldn’t find it. I am trying 
   to create an if statement where it displays a certain image, unless I specify
   a different image for a certain category.
 * I have this:
    ` <?php if (in_category('1') ): ?> <img src='/images/teams.jpg'/
   > <?php elseif in_category('4') ): ?> <img src='/images/child-sponsorship.jpg'/
   > <?php else: ?> <img src='/images/home-image.jpg' /> <?php endif; ?>

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

 *  [Medizinische Abkuerzungen](https://wordpress.org/support/users/stefansuedfeld/)
 * (@stefansuedfeld)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/php-help-1-3/#post-418224)
 * <?php
    if (in_category(‘1′)) echo “<img src=’/images/teams.jpg’ />”; elseif (
   in_category(‘4′)) echo “<img src=’/images/child-sponsorship.jpg’ />”; else echo“
   <img src=’/images/home-image.jpg’ />”;?>
 *  [moshu](https://wordpress.org/support/users/moshu/)
 * (@moshu)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/php-help-1-3/#post-418225)
 * Does this help?
    [http://codex.wordpress.org/Conditional_Tags](http://codex.wordpress.org/Conditional_Tags)
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 9 months ago](https://wordpress.org/support/topic/php-help-1-3/#post-418226)
 * I hate using if followed by colons. Hard to read and understand.. Bah. I’m also
   not a big fan of continually opening and closing the PHP blocks every other line.
 * Try this instead:
    `<?php  if (in_category('1')) { echo "<img src='/images/teams.
   jpg' />"; }  else if (in_category('4')) { echo "<img src='/images/child-sponsorship.
   jpg' />"; }  else { echo "<img src='/images/home-image.jpg' />"; } ?>
 * See how much nicer that is? Spaced out, easy to read, groups the bits together
   naturally… just nicer, IMO. Works too. 🙂
 *  Thread Starter [jefft](https://wordpress.org/support/users/jefft/)
 * (@jefft)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/php-help-1-3/#post-418257)
 * Thanks for all your help! But I’m still having a problem…the home page displays
   does not display the “else” image, but rather, the image from the corresponding
   category of the first post. Suggestions?
 *  Thread Starter [jefft](https://wordpress.org/support/users/jefft/)
 * (@jefft)
 * [19 years, 9 months ago](https://wordpress.org/support/topic/php-help-1-3/#post-418258)
 * Not first post, but most recent post. (The first one WP displays.)
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 9 months ago](https://wordpress.org/support/topic/php-help-1-3/#post-418324)
 * jefft: Add an “if (is_home()) { blah blah }” to the beginning of the series of
   if statements. That way, you can explicitly define what you want on the home 
   page.

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

The topic ‘PHP Help’ is closed to new replies.

 * In: [Requests and Feedback](https://wordpress.org/support/forum/requests-and-feedback/)
 * 6 replies
 * 4 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [19 years, 9 months ago](https://wordpress.org/support/topic/php-help-1-3/#post-418324)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
