Jump to content

Dynamic IMG SRC Specification


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 post
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 post
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.

https://www.w3schools.com/php/php_looping_foreach.asp

Edited by dsonesuk
Link to post
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

slider.txt

Link to post
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>
</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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...