1

I have created an if statement inside the "else" of an if/else statement.It works.However the code below the function does not run.When i remove the function the code below the function runs.Could you please help me out.

This code causes the problem:

<?php $googleplay= get_option('director_googleplay');?>
<?php if($googleplay): ?>
    <a href="<?php print $googleplay; ?>">
       <img src="<?=IMAGES?>/googleplay.png" class=" img-responsive  top-buffer-5"  alt="Image"/>
    </>
<?php endif;;?> 

The php:

<?php  $category_id = get_cat_ID('Category Name'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

    <?php if ( in_category("1") ) { ?>
       <div class="section"></div>

    <?php } elseif ( in_category("2") ) { ?>
       <div class="section"></div>

  <?php } else { ?>
      <div class="section">
          <?php $googleplay= get_option('director_googleplay');?>
          <?php if($googleplay): ?>
              <a href="<?php print $googleplay; ?>"><img src="<?=IMAGES?>/googleplay.png" class=" img-responsive  top-buffer-5"  alt="Image"/></>
          <?php endif;;?> 
       </div>
    <?php } ?>
<?php endwhile;else: ?>
    <p>Sorry, no posts matched your criteria.</p>
<?php endif; ?>

<div class="section">
    <?php $facebook= get_option('director_facebook');
    <?php if($facebook): ?>
    <a href="<?php print $facebook; ?>"><img src="<?=IMAGES?>/Facebook.png" class=" img-responsive pull-left"alt="Image"/></>
    <?php endif; ?>
</div>
10
  • 1
    Good grieve, people still write code using that embedded style of php? Commented Feb 7, 2014 at 10:01
  • 1
    First, what is the error message you are getting? Second, the short and the long versions are not the same. Third, "the php" has an unidentified endwhile in there. Among other errors. Commented Feb 7, 2014 at 10:01
  • @arkascha: There's nothing wrong with that style. The problem here is that the code is a mess because there's too much embedded logic and the granularity is not quite right. Commented Feb 7, 2014 at 10:03
  • 1
    arkascha: Wordpress forces you. This is the only way for templates. Commented Feb 7, 2014 at 10:05
  • @Jon: I never said something is wrong with the style. It is just that such code is a mess because there's too much embedded logic. ;-) Commented Feb 7, 2014 at 10:05

1 Answer 1

1

Well, you forgot to close the <a>-Tag: </a>, not </>. However, the Code should still "run", just display garbage.

Additionally, php snippets can also be started and ended by the <?-Tag, you have one of those in your code:

<img src="/googleplay.png" class=" img-responsive top-buffer-5" alt="Image"/>

should work. Remove <?=IMAGES?> which probably causes the problem. What are you trying to do with <?=IMAGES?>?

Sign up to request clarification or add additional context in comments.

2 Comments

Hi nekaab. I am using the <?=IMAGES?> to retrieve code from the functions where <?=IMAGES?> is acting to get the location of the images.
Ok i got it working by adding an extra else statement to it. Though it doesn't make sense.Must be some wordpress error

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.