Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

embedding php/xml banner slideshow...

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 06-22-2007, 02:20 PM
 
dub713 dub713 is offline
 

Advanced Member
  
Join Date: May 2007
Posts: 56
 

Default embedding php/xml banner slideshow...

while i'm sure there are some better ways to do this, for the sake of what i thought would have been simplicity i just want to use an existing php/xml setup to display rotating banners and images.

well, when i go to drop it all in there i get a smarty error, and i have no idea how the heck to fix this.

i will post all code in case anyone wants to use something like this.

so, to start...

this is the main php. it was in the head of the old pages, but it could go in it's own php file correct?

Code:
<?php # # $Id: slideshow.php,v 1.30.2.5 2007/03/22 13:54:22 svowl Exp $ # $depth = array(); function startElement($parser, $name, $attrs) { global $depth; global $slides, $feature, $banners; if ($name=='SLIDE') { $slides[] = $attrs; } if ($name=='FEATURE') { $feature[] = $attrs; } if ($name=='BANNER') { $banners[] = $attrs; } $depth[$parser]++; } function endElement($parser, $name) { global $depth; $depth[$parser]--; } function readXML($file) { $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startElement", "endElement"); if (!($fp = fopen($file, "r"))) { die("could not open XML input"); } while ($data = fread($fp, 4096)) { xml_parse($xml_parser, str_replace('&','&amp;',$data), feof($fp)); /*if (!xml_parse($xml_parser, $data, feof($fp))) { die (sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); }*/ } xml_parser_free($xml_parser); } #### readXML("features.xml"); $nums = array_rand($feature,3); foreach($nums as $k => $i) { $v = $feature[$i]; print " <td width=\"164\" align=\"center\">\n"; print " <a href = \"{$v['HREF']}\"><img src=\"{$v['SRC']}\" alt=\"{$v['TITLE']}\" border=\"0\" height=\"125\" width=\"125\"></a><br>\n"; print " <a href = \"{$v['HREF']}\"><font face=\"arial\" size=\"2\">{$v['TITLE']}</font></a>\n"; print " </td>\n"; } ?>

then, in the page itself, you have the elements to display our rotating banner ads/slideshow...

Code:
<? readXML("banners.xml"); $nums = array_rand($banners,2); foreach($nums as $k => $i) { $v = $banners[$i]; print " <p><a href = \"{$v['HREF']}\"><img src=\"{$v['SRC']}\" alt=\"{$v['TITLE']}\" border=\"0\"></a></p>\n"; } ?> </td> <? readXML("features.xml"); $nums = array_rand($feature,3); foreach($nums as $k => $i) { $v = $feature[$i]; print " <td width=\"164\" align=\"center\">\n"; print " <a href = \"{$v['HREF']}\"><img src=\"{$v['SRC']}\" alt=\"{$v['TITLE']}\" border=\"0\" height=\"125\" width=\"125\"></a><br>\n"; print " <a href = \"{$v['HREF']}\"><font face=\"arial\" size=\"2\">{$v['TITLE']}</font></a>\n"; print " </td>\n"; } ?>

lastly, add all the images into an XML file names banners.xml or features.xml which contains this...

<banners>
<banner src="images/banner_2.jpg">
<banner src="images/banner_24.gif">
<banner src="images/banner_25.gif" href="IF YOU WANT TO LINK" />
<banner src="images/banner_26.gif">
<banner src="images/banner_27.gif">
</banners>

<features>
<feature src="images/image.jpg" href="link" title="title"/>
<feature src="images/image.jpg" href="link" title="title"/>
</features>


questions....

when i embed the code into the page, do you embed it with the <? and ?> ?

why am i getting this error?

Error: Smarty error: [in today_news.tpl line 22]: syntax error: unrecognized tag: $v['SRC'] (Smarty_Compiler.class.php, line 436) in /htdocs/www/store/Smarty-2.6.12/Smarty.class.php on line 1095

and why are these characters displaying?

$i) \">\n"; } ?>

i know it has to do with the print function, and that you have to tell the code to display corrrectly so you tell it to not read or print what's after the \ but i'm just not figuring out what i need to do to get this working.

anyone have any ideas?

thanks,
__________________
X-Cart version 4.1.7 - PHP 5.2. - MySQL server 5.0.41-community-nt - MySQL client 5.0.22 - Web server Apache/2.2.4 (Win32) - PHP/5.2.2
Reply With Quote
  #2  
Old 06-22-2007, 02:50 PM
 
dub713 dub713 is offline
 

Advanced Member
  
Join Date: May 2007
Posts: 56
 

Default Re: embedding php/xml banner slideshow...

well, i just found a random image mod, and will have to test it, but it would be great to see a solution to this. it seems like a relatively easy fix, as it looks like it's just not recognizing SRC, or maybe something else.

This random image generation with the XML is a really simple thing, since all you have to do is add an image src to the XML file and you're done. i think it would be great for some of the other folks in here that aren't as comfortable or lack the knowledge to implement a lot of these mods. this could be used without having to patch/upgrade, or modify bunch of different files.


call it a begginer mod.

thanks
__________________
X-Cart version 4.1.7 - PHP 5.2. - MySQL server 5.0.41-community-nt - MySQL client 5.0.22 - Web server Apache/2.2.4 (Win32) - PHP/5.2.2
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:06 AM.

   

 
X-Cart forums © 2001-2020