Solved

need help with php condition

Posted on 2013-05-21
3
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Suggested Solutions

Title # Comments Views Activity
Help with mod_substitute 18 76
migrating to phpbb forum from vBulletin 4.2 3 94
emailing registered email addresses in phpmyadmin 5 67
Best hashing method? 1 20
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

734 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