PHP for loop () with links

What I'm trying to do: create a numbered list of images with links to each image. List numbers are not sequential.

Variables:

  • $image->number - gives the first number;
  • $image->next_pid - gives the following 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 contains a list of numbered lists that I need. I cannot figure out how to include the "next link" variable in a loop.

Example: number = 1; next_pid = link_ID2; total = 7. Thus, the list will look like this: 1 (without link) 2 (with link_ID2) 3 (link_ID3), etc. to 7. There is no link in the first image because it is already displayed. Sorry for not being clear enough.

You can see what I'm trying to do here . I have listed other photos in this gallery, but without a link. This is a wordpress site and a plugin that I use to display images in each gallery. You can view the PasteBin functions.php of this plugin.

+4
source share
1 answer

EDIT: That 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; } ?> 

Bit $list_first = $image->number; Useless as you rewrite it shortly after in a for loop.

An extra line has been added so as not to display a link for the current image.

+1
source

Source: https://habr.com/ru/post/1435371/


All Articles