Hi - can anyone help?
I'm new to PHP land, and failing at this particular part.
I have an image slider - where each image is contained in a div (e.g it is not a slider using ul and il...)
It is will be used in a template for many pages, which will each have a varying number of images.
There for I need to create a loop that say 'when there is no img url found, return to img 1'
I'm stump. Currently this is beyond me
.....
Or do I need to start from scratch? (ARGH!)
Here is my function
function getImage($num) {
global $more;
$more = 1;
$link = get_permalink();
$content = get_the_content();
$count = substr_count($content, '<img');
$start = 0;
for($i=1;$i<=$count;$i++) {
$imgBeg = strpos($content, '<img', $start);
$post = substr($content, $imgBeg);
$imgEnd = strpos($post, '>');
$postOutput = substr($post, 0, $imgEnd+1);
$postOutput = preg_replace('/width="([0-9]*)" height="([0-9]*)"/', '',$postOutput);;
$image[$i] = $postOutput;
$start=$imgBeg+$imgEnd+1;
}
if(stristr($image[$num],'<img')) { echo '<a href="'.$link.'">'.$image[$num]."</a>"; }
$more = 0;
}
and here's how I use it in the html:
<div class="project-slider-mask w-slider-mask">
<div class="w-slide">
<?php getImage('1'); ?>
</div>
<div class="w-slide">
<?php getImage('2'); ?>
</div>
<div class="w-slide">
<?php getImage('3'); ?>
</div>
<div class="w-slide">
<?php getImage('4'); ?>
</div>
etc etc etc
Help much much appreciated....been failing at this for so long!