Jump to content

Dynamic IMG SRC Specification

Harry Muhren

Recommended Posts

I have looked at your manual and automatic slider ‘how to examples’, in which the img src paths are set for each media library image separately - with their absolute paths. I have written a php snippet in which the urls of a number of the most recent uploaded images are determined. I can’t find out how this snippet can be combined with the html (css and javascript) code. Could you please provide a suggestion how to tackle this, using the php code or another way of getting the most recent uploaded media library images in a slider, without the need to set the absolute paths individually.

Thanks - Harry

Link to comment
Share on other sites

Thanks dsonesuk! In my php code snippet, indeed, I save the urls in a php array. The problem, however, is how to integrate this in de html code in for instance the examples given in the ‘how to’ html code of a slider. Maybe you can give me a piece of example code. Thanks in advance- regards - Harry

Link to comment
Share on other sites

Its not that hard? Learn how loop through each array item, with for instance a foreach loop, echo out each item in array, once you have that, then add string content that will be the html up to img src=" then learn to add php loop array value between quotes of src attribute.


Edited by dsonesuk
Link to comment
Share on other sites

Dear dsonesuk,

The php function code by itself is no problem, but how to combine that with html, css and javascript. I have attached the slider code, with three lines of php code, which I have tried to run on the w3schools website in the 'how to' section, but without succes. Obviously, the php is ignored. Perhaps yo can provide a last hint!?

By the way, can you tell how I can change my display name?

Thanks - regards - Harry


Link to comment
Share on other sites

All you have to do is produce on each loop

<div class="mySlides fade">
  <div class="numbertext">1 / 3</div>
  <img src="img_nature_wide.jpg" style="width:100%">
  <div class="text">Caption Text</div>
With text in red as the stored item value in php array.

echo '<div class="mySlides fade">';
  echo '<div class="numbertext">1 / 3</div>';
  echo '<img src="'.$img_in_array.'" style="width:100%">';
  echo '<div class="text">Caption Text</div>';
echo' </div>';

then do the same with

<span class="dot" onclick="currentSlide(1)"></span> 

using a counter to reproduce individual dots for each image to total of items in array

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...