You are here:  » Thumbnails


Thumbnails

Submitted by dustin on Sun, 2006-03-26 17:40 in

I have a rss that has html for thumbnails (images).

What is the best way to loop these so they will show up no the page correctly.

I would like to be able to specify how many will go on each row and I would also like to limit the number taken from the rss. Like only use the first 10.

Submitted by dustin on Sun, 2006-03-26 17:46

<rss version="2.0">

<channel>
<title>TITLE HERE</title>

<link>
http://www....com/affid
</link>
<description>Quick description</description>
<language>en-us</language>

<item>

<title>
Title of the image
</title>

<link>
http://www...WHERE YOU GO AFTER CLICKING ON THE IMAGE...com
</link>

<description>
<a href="/Link you go to after clicking on the image" target="_blank"><img src="/image location" width="100" height="133" border="0" alt="title of the image"></a>
</description>
<pubDate>Wed, 22 Mar 2006 00:00:01 EST</pubDate>
</item>
</channel>
</rss>

Also their will be text under the image. Above you see that is has the title of the image and the link before the image...that will be under the image.

Submitted by support on Sun, 2006-03-26 17:49

Hi dustin,

To answer the second question first; you stop MagicParser from reading the file you need to return "true" from your myRecordHandler function. So, if you only want to process the first 10, you need a global counter variable; which you increment for each item. When it reaches the maximum value you want, you return true. For example:

<?php
  $counter 
0;
  function 
myRecordHandler($record)
  {
    global 
$counter;
    
// process $record as normal
    // incremement $counter
    
$counter++;
    
// if $counter = 10, return true
    
return ($counter == 10);
  }
  
MagicParser_parse("file.xml","myRecordHandler");
?>

With regards to printing thumbnail images into a table with so many on each row; you could make use of the same counter variable to start a new row every so many items. For example:

<?php
  $counter 
0;
  print 
"<table>";
  print 
"<tr>";
  function 
myRecordHandler($record)
  {
    global 
$counter;
    
// display $record as required in a table cell (<td>)
    
print "<td>";
    print 
"<a href='".$record["LINK"]."'>".$record["DESCRIPTION"]."<br />".$record["TITLE"]."</a>";
    print 
"</td>";
    
// incremement $counter
    
$counter++;
    
// if $counter divisible by 4 (for 4 columns), start a new row
    
if (!($counter 4))
    {
      print 
"</tr>";
      print 
"<tr>";
    }
    
// if $counter = 10, return true
    
return ($counter == 10);
  }
  print 
"</tr>";
  print 
"</table>";
  
MagicParser_parse("file.xml","myRecordHandler");
?>

Hope this helps!

Submitted by dustin on Mon, 2006-03-27 00:43

Could I make it so I can splice in another XML file that I create...

Submitted by dustin on Mon, 2006-03-27 02:41

For some reason the top row is offset from the additional row.

It is up about 30 pixels and over on the right side of the page.

Submitted by dustin on Wed, 2006-04-05 00:36

Any ideas why the HTML is messed up?

Submitted by support on Wed, 2006-04-05 04:08

Hi dustin,

Can you post the exact code you are using and the URL of the feed as I can't see any reason why the HTML would not be displayed properly, other than the first item not containing any data (and therefore printing out an empty cell). The only other thing that could have an effect is external CSS controling the table display, but that shouldn't be an issue.

Cheers,
David.