4

What I'm trying to do: create a numbered list of pictures with links to each picture. The list numbers are not consecutive.

Variables:

  • $image->number - gives the first number;
  • $image->next_pid - gives the "next link";
  • $image->total - gives the last number;

Code:

<?php 
$list_first = $image->number;
$list_last = $image->total;
for ($list_first = 1; $list_first <= $list_last; $list_first++) {
    echo($list_first);
}
?>

Problem: this code lists the numbered list of pictures that I need. What I can't figure out is how to include the "next link" variable into the loop.

Example: number = 1; next_pid = link_ID2; total = 7. So the list will look like this: 1 (without link) 2 (with link_ID2) 3 (link_ID3) etc. until 7. The first picture doesn't have a link because it's already showing. Sorry for not being explicit enough.

You can view what I'm trying to do here. I've listed the other pictures in that gallery but without a link. It's a wordpress site and a plugin I'm using to display the pictures in each gallery. You can view on PasteBin the functions.php of that plugin.

11
  • Are the numbers sequential, or arbitrary? Commented Sep 20, 2012 at 20:10
  • Use a while loop instead. While the next one is not null... Commented Sep 20, 2012 at 20:14
  • Sequential (1,2,3,4 etc) Commented Sep 20, 2012 at 20:15
  • So this is like a pagination display, where number might contain 5, total might contain 10, and next_pid contains a link to the page that shows 11 - 15? Commented Sep 20, 2012 at 20:17
  • 1
    And can you also include a var_dump($image)? Because I can't figure out what it structure might be. Commented Sep 20, 2012 at 20:27

1 Answer 1

1

EDIT: This should do the trick.

<?php 

$list_last = $image->total;
for ($i = 1; $i <= $list_last; $i++)
  {
  if ($_GET['pid'] != $i) echo "<a href='http://www.noahd.net/demo-upwall/residential/rooftop-garden/15/?pid=".$i."'> ".$i." </a>";
  else echo $i;
  }
?>

The bit $list_first = $image->number; is of no use as you overwrite it shortly after in the for loop.

Added an extra line not to display a link for the current image.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.