logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 11-16-2011, 10:14 AM   #1
cocoonfx
cocoonfx's Avatar
 
Join Date: Nov 2006
Location: Tamworth,UK
Posts: 576
Default Looping an Image

Hi Guys

I have 10 images called Banner1.jpg to Banner10.jpg

Existing code:
<a href=""><img src="<?php echo get_template_directory_uri();?>/images/banner1.jpg" alt="" title=""/></a>

I want to dynamic pull the images using PHP. I am trying to use the following:

<?php
$i=0;
do
{
$i++;
echo "<a href="">"."<img src=\"images\banner" .$i . ".jpg></a>"\n";
}
while ($i<=10);
?>

However I am getting a T error and I can not work out what I am doing wrong. Any assistance would be appreciated.
cocoonfx is offline   Reply With Quote
Old 11-20-2011, 04:47 PM   #2
cocoonfx
cocoonfx's Avatar
 
Join Date: Nov 2006
Location: Tamworth,UK
Posts: 576
Default

Can anyone assist?
cocoonfx is offline   Reply With Quote
Old 11-21-2011, 12:12 AM   #3
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

directory_uri typo?

and
echo "<a href="">"."<img src=\"images\banner" .$i . ".jpg></a>"\n";
looks wrong.
href "link"
also de bug by echoing individual strings ( such as $1
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is online now   Reply With Quote
Old 11-21-2011, 12:18 AM   #4
cocoonfx
cocoonfx's Avatar
 
Join Date: Nov 2006
Location: Tamworth,UK
Posts: 576
Default

Hi Edbr

The directory_uri is actually correct. I am changing an existing wordpress template. Looks odd I know.
cocoonfx is offline   Reply With Quote
Old 11-21-2011, 12:58 AM   #5
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,164
Default

Ah. whats the actual error say? is there a line number?
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is online now   Reply With Quote
Old 11-21-2011, 06:03 AM   #6
DWcourse
DWcourse's Avatar
 
Join Date: Apr 2009
Posts: 3,276
Default

Code:
echo "<a href="">"."<img src=\"images\banner" .$i . ".jpg></a>"\n";
You've escaped some of the quotation marks (the one before images) and not others. And for WordPress you need to use / as the separator not \
__________________
If my answer helped, check out DWcourse.com for Dreamweaver tips and tutorials.
DWcourse is offline   Reply With Quote
Old 11-21-2011, 01:44 PM   #7
cocoonfx
cocoonfx's Avatar
 
Join Date: Nov 2006
Location: Tamworth,UK
Posts: 576
Default

so it should be ?

echo "<a href="">"."<img src=/images/banner .$i . ".jpg></a>"\n";
cocoonfx is offline   Reply With Quote
Old 11-22-2011, 11:50 AM   #8
cocoonfx
cocoonfx's Avatar
 
Join Date: Nov 2006
Location: Tamworth,UK
Posts: 576
Unhappy

Ok I have managed to get the code to work 80% of the way.

Please see below.

<?php
$u= '/dev/images/banner';
$f='.jpg';
$i=0;
do
{
$i++;


echo "<img src=".$u."".$i."".$f.">\n";

}
while ($i<9);
?>

However wordpress uses the following to pull the full director path

<?php echo get_template_directory_uri();?>

i.e www.domainname.co.uk/dev/

However I can not get this part now to work. I have tried:

$p= <?php echo get_template_directory_uri();?>;

I get a T error. Any ideas on how to get this part to work?
cocoonfx is offline   Reply With Quote
Old 11-22-2011, 03:28 PM   #9
DWcourse
DWcourse's Avatar
 
Join Date: Apr 2009
Posts: 3,276
Default

if you're setting a variable, don't use echo. Echo writes to the screen.
__________________
If my answer helped, check out DWcourse.com for Dreamweaver tips and tutorials.
DWcourse is offline   Reply With Quote
Old 11-22-2011, 03:51 PM   #10
cocoonfx
cocoonfx's Avatar
 
Join Date: Nov 2006
Location: Tamworth,UK
Posts: 576
Default

Thanks DW and Edbr for directing me in the right direction and making me problem solve this... this works below very well.

<?php
$u= '/images/banner';
$p= get_template_directory_uri();
$f='.jpg';
$i=0;
do
{
$i++;


echo "<img src=".$p."".$u."".$i."".$f.">\n";

}
while ($i<9);
?>
cocoonfx is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:27 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com