Gary Samuels
asked on
need help with php condition
This php code is working and creates 'previous' and 'next' button style links for a photo gallery.
<a href="<?php the_permalink(); if($i> 0) {echo $i-1;} elseif($i!=0) {echo $i;} ?>" class="btn-1 btn-align-left btn-previous"><i> </i><b><span><?php printf ( __( 'Previous photo' , 'rayoflight' ));?></span></b><u> </u></a>
<a href="<?php the_permalink(); if($i+1 < $count) {echo $i + 1;} elseif($i!=0) {echo $i;} ?>" class="btn-1 btn-align-left btn-next"><i> </i><b><span><?php printf ( __( 'Next photo' , 'rayoflight' ));?></span></b><u> </u></a>
But if I have a single image (count would = 0) the buttons still show up. The links don't jump anywhere but the buttons are still showing. How can I change the code so the buttons do not appear if there is no previous or next image?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I ended up using this:
<?php if($i > 0) { ?>
<a href="<?php the_permalink(); if($i> 0) {echo $i-1;} elseif($i!=0) {echo $i;} ?>" class="btn-1 btn-align-left btn-previous"><i> </i><b><span><?php printf ( __( 'Previous photo' , 'rayoflight' ));?></span></b><u> </u></a>
<?php } ?>
<?php if($count > 1) { ?>
<a href="<?php the_permalink(); if($i+1 < $count) {echo $i + 1;} elseif($i!=0) {echo $i;} ?>" class="btn-1 btn-align-left btn-next"><i> </i><b><span><?php printf ( __( 'Next photo' , 'rayoflight' ));?></span></b><u> </u></a>
<?php } ?>
ASKER