construction does not work does not accept elseif WITHOUT ELSE everything works

<?phpif (get_post_meta($post->ID, 'close_quest', true)==false ) : ?> <div id="stars">.........</div> <? elseif; ?> <div id="link">.........</div> <? endif; ?> 

How can I be in if and else to build in large html lines

So it also works well, I would like a little more compact

 <?php if (get_post_meta($post->ID, 'close_quest', true)==false ) : ?> <div id="stars">.........</div> <? elseif (get_post_meta($post->ID, 'close_quest', true)==true ) : ?> <div id="link">.........</div> <? endif; ?> 
  • To do this, you must first understand why you need elseif. As soon as you yourself understand what you want to do, the problem will be solved by itself - Ipatiev
  • Hmm, I have an arbitrary field check true / false in WordPress - Anton

1 answer 1

else if you need a condition inside parentheses, and you; (and separate if from the initial php tag) example:

 <?php if (get_post_meta($post->ID, 'close_quest', true)==false ) { ?> <div id="stars">.........</div> <? } else if(1==1) { ?> <!-- условие для примера --> <div id="link">.........</div> <? } ?> 

If you do not need additional checking in elseif, you can put else, an example below:

 <?php if (get_post_meta($post->ID, 'close_quest', true)==false ) { ?> <div id="stars">.........</div> <? } else { ?> <div id="link">.........</div> <? } ?> 
  • <? phpif (get_post_meta ($ post-> ID, 'close_quest', true) == false):?> <div id = "stars"> ......... </ div> <? endif; ?> this coadd works well - Anton
  • Thanks, it works fine - Anton