Link to home
Start Free TrialLog in
Avatar of Gary Samuels
Gary SamuelsFlag for United States of America

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>&nbsp;</i><b><span><?php printf ( __( 'Previous photo' , 'rayoflight' ));?></span></b><u>&nbsp;</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>&nbsp;</i><b><span><?php printf ( __( 'Next photo' , 'rayoflight' ));?></span></b><u>&nbsp;</u></a>

Open in new window

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
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gary Samuels

ASKER

Answered my question exactly as I ask.
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>&nbsp;</i><b><span><?php printf ( __( 'Previous photo' , 'rayoflight' ));?></span></b><u>&nbsp;</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>&nbsp;</i><b><span><?php printf ( __( 'Next photo' , 'rayoflight' ));?></span></b><u>&nbsp;</u></a>
<?php } ?>

Open in new window