| Tweet | ||
| Pin It |
Google just announced an image sitemap format which will help get images from your site indexed. I thought this was a perfect extension to the datafeed series.
The first step is to make Google think we have the images on our server. So inside an “images” folder, create “image.php” like so:
<?php
include('../vars.php');
$cQuery = "select * from products where ProductID=" . (int)$_GET['ProductID'] . " limit 1";
$oResult = mysql_query($cQuery);
$rsData = mysql_fetch_array($oResult);
header('Content-Type: image/jpeg');
$fp = fopen($rsData['Thumbnail'], "r");
fpassthru($fp);
fclose($fp);
exit();
?>
next, at the root of the site, create images.php:
<?php
header('Content-Type: text/xml');
include("./vars.php");
?><<?= '?' ?>xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<?php
$aProductsToInclude = array("Green Tea", "White Tea", "Black Tea", "Oolong Tea", "Iced Tea");
$cQuery = "select * from products where (";
foreach ($aProductsToInclude as $cCategory) {
$cQuery .= "MerchantSubcategory like '%" . $cCategory . "%' or MerchantCategory like '%" . $cCategory . "%' or ";
} // ends foreach ($aProductsToInclude as $cCategory)
$cQuery = ereg_replace(" or $", ")", $cQuery);
$cQuery .= " and Thumbnail<>'' order by Name";
// echo("$cQuery");
$oResult = mysql_query($cQuery);
while ($rsData = mysql_fetch_array($oResult)) {
?>
<url>
<loc>http://www.greenwhiteandblacktea.com/<?= simplify($rsData['Name']) ?>-p<?= $rsData['ProductID'] ?>.php</loc>
<image:image>
<image:loc>http://www.greenwhiteandblacktea.com/images/<?= simplify($rsData['Name']) ?>-i<?= $rsData['ProductID'] ?>.jpg</image:loc>
<image:caption><?= $rsData['Name'] ?></image:caption>
</image:image>
</url>
<?php
} // ends while ($rsData = mysql_fetch_array($oResult))
?>
</urlset>
What this does is creates an image sitemap file.
Finally, add to your .htaccess:
RewriteRule ^images/(.*)\-i([0-9]+).jpg$ images/image.php?ProductID=$2 [L] RewriteRule ^images.xml$ images.php [QSA]
Now, you have an image sitemap (images.xml) and when you visit an image URL like http://www.greenwhiteandblacktea.com/images/Bao-Zhong-Royale-Oolong-i469648571.jpg , htaccess gets the productID, using fopen opens the image, and passes it through to the browser.
If you were slick, you’d add some error checking and caching to these scripts to make things go quicker.
The tea niche may not be ideal for someone searching for images (think shoes!) but this at least gives you an idea of how to take advantage of this new tool by Google.
Turn Datafeeds Into Affiliate Store In 3 Easy Steps - No HTML Knowledge
Custom programmed datafeed sites can be a little too mcuh for some people. That's ok! That's why there's Datafeedr.
If you think building an affiliate store was just too hard, then Datafeedr's Click & Create
system is just what you've been waiting for. Even if you have no experience with web design at all, you can have your own datafeed-driven affiliate site up and running today. Watch the video NOW and see this Push-Button Store Creation System in action!





{ 4 comments… read them below or add one }
I got an error when running images.php
XML Parsing Error: no element found
Location: http://mydomain.com/images.php
Line Number 7, Column 1:
@Panda – contact me w/ your actual domain & error. Looks like an XML error, not PHP
Well, it’s the tea site, wegottea.com, and mostly your code. I just added two fields to line 9.
$aProductsToInclude = array(“Green Tea”, “White Tea”, “Black Tea”, “Oolong Tea”, “Iced Tea”,”Tea Cups”,”Tea Pots”);
Could it be i was saving the file as ANSI instead of UTF-8 ?? I just realized my notepad++ was set to ANSI. Now, should I use UTF-8 with or without byte order mark?
{ 1 trackback }