Skip to content
Advertisement

Display pictures from a folder in the specific way – PHP

I am trying to create a dynamic gallery in php with specific order of pictures on the page, but I can’t find the function or piece of php code to do so.

Conditions:

  1. The gallery must be dynamic, pictures will be coming from a folder via php, because when I’ll add/upload more pictures in the folder they must be displayed on the page without adding manually the html tags in. ( this part is easy, problem is the condition 2 ).
  2. The first row will have 5 pictures, the second – 4 pictures (important for the specific effect).

My code:

JavaScript

The code works well, but it just displays 9 pictures obviously. I was unable to make it dynamic displaying 5 pictures first, 4 pictures after and stay this way in a loop till displays all pictures from that folder.

Advertisement

Answer

You can take advantage of the array_splice function that removes elements from the array everytime it returns those elements :

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement