Solved

need help with php condition

Posted on 2013-05-21
3
223 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:garysamuels
  • 2
3 Comments
 
LVL 82

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:garysamuels
ID: 39186109
Answered my question exactly as I ask.
0
 

Author Comment

by:garysamuels
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now