Solved

need help with php condition

Posted on 2013-05-21
3
232 Views
Last Modified: 2013-05-21
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?
0
Comment
Question by:Gary Samuels
  • 2
3 Comments
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39186060
<?php if(count > 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>
<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

0
 

Author Closing Comment

by:Gary Samuels
ID: 39186109
Answered my question exactly as I ask.
0
 

Author Comment

by:Gary Samuels
ID: 39186114
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

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question