3

Any help with figuring out why I get 'else' (T_ELSE) in your code on line in the code below?

 <?php if ( is_category( '3' ) )  ?>
        <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image1.png"></a></td>

  <?php if ( is_category( '1096' ) )  ?>
        <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image2.png"></a></td>

  <?php if ( is_category( '1437' ) )  ?>
        <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image3.png"></a></td>

  <?php if ( is_category( '1150' ) )  ?>
        <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image4.png"></a></td>

  <?php if ( is_category( '1138' ) )  ?>
        <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image.png"></a></td>

  <?php if ( is_category( '3' ) )  ?>
        <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image5.png"></a></td>

  <?php else : ?>
        <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image6.png"></a></td>
    <?php endif; ?>
6
  • you need to use : after the closing ) with this if usage. Commented Jun 16, 2015 at 19:26
  • I don't like this "if" usage, there are so many "<?php . . . ?>. Why not a "switch" with an "echo" for each "case"? Commented Jun 16, 2015 at 19:33
  • Actually your code seems too bit really redundant, you should shrink it a lot, @user3512391 Commented Jun 16, 2015 at 19:35
  • @JoseManuelAbarcaRodríguez Yeah that sounds good. But wouldn't it cause issues when echoing a relative url? As in the echo is a wordpress function. Wouldn't I have to hard code the img src url to make the echo work? Commented Jun 16, 2015 at 19:42
  • @user3512391, the idea is to remove so many "<?php . . . ?>". The rest of your code remains almost the same. But, if this style works for you, stick to it! Commented Jun 16, 2015 at 19:44

1 Answer 1

2

Format your IF statement like so:

      <?php if (is_category('3')) : ?>
            <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image.png"></a></td>

      <?php elseif (is_category('1096')) : ?>
            <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image.png"></a></td>

      <?php elseif (is_category('1437')) : ?>
            <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image.png"></a></td>

      <?php elseif (is_category('1150')) : ?>
            <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image.png"></a></td>

      <?php elseif (is_category('1138')) : ?>
            <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image.png"></a></td>

      <?php elseif (is_category('3')) : ?>
            <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image.png"></a></td>

      <?php else : ?>
            <td class="logo-alts"><a href="/"><img src="<?php bloginfo('template_directory'); ?>/_images/image.png"></a></td>
        <?php endif; ?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.