Hi David
I have tried making my own breadcrumbs
<p>You are at <a href="/">Home</a> » <a href="/category/<?php print $mainProduct["category"]; ?>"><?php print $mainProduct["category"]; ?></a> » <?php print $mainProduct["name"]; ?></p>
by pulling the category name as the link destination, but it's not hyphenated and therefore reaches a 404. How can I link to the category or hyphenate the category name please?
Thanks
Phil
Thanks Dave; I've gone and broken it again now!
I've chopped off product/ and category/ in the .htaccess. I think I've found all instances of links and fixed them except for the category link in the breadcrumbs described above. How do I fix it please so it doesn't start category/?
Thank you
Phil
I really am stupid. I put in the category/ myself in the link and only just noticed when I read over the original message!
Thanks anyway!
Sorry to bother you again, I really have broken it this time. I have a blog attached in a subdirectory, but when I try accessing it, it redirects to a category page trying to find a category with the name 'blog'. I'm guessing I the .htaccess is wrong?
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(.*).html$ products.php?q=$1&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^review/(.*).html$ reviews.php?q=$1&rewrite=1&%{QUERY_STRING} [L]
RewriteRule ^merchant/$ merchants.php
RewriteRule ^merchant/(.*)/$ search.php?q=merchant:$1:&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^merchant/(.*)/(.*).html$ search.php?q=merchant:$1:&page=$2&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^category/$ categories.php
RewriteRule ^(.*)/$ search.php?q=category:$1:&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^(.*)/(.*).html$ search.php?q=category:$1:&page=$2&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^brand/$ brands.php
RewriteRule ^brand/(.*)/$ search.php?q=brand:$1:&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^brand/(.*)/(.*).html$ search.php?q=brand:$1:&page=$2&rewrite=1%{QUERY_STRING} [L]
Kind regards
Phil
And whilst I'm pestering you, may I have one more question? I have put the breadcrumbs above into searchresults.php so that when you're in a category, it displays You are at Home > Category.
Of course, the search results then use one of the categories of the products in the results in the breadcrumbs. Is there a way of making the breadcrumb different if a search has actually been conducted?
E.g. a customer is on a category page
You are at Home > Category
A customer did a search
You are at Home > Search (or Search Query?)
Promise I'll stop now (well, until tomorrow! :P )
Hi Phil,
The /blog/ folder is being caught by the following rule...
RewriteRule ^(.*)/$ search.php?q=category:$1:&rewrite=1%{QUERY_STRING} [L]
I wouldn't recommend using a top-level "virtual folder" rewrite, and in this case I would suggest reverting back to /category/ for the category re-writes; exactly as you have for the brand rewrites.
Alternatively, you could add a RewriteCond statment (immediately after RewriteBase) to exlude /blog/, like this:
RewriteCond %{REQUEST_URI} !^/blog/.*$
For your breadcrumbs, I guess one way to tell if a search rather than a category browse had led to the product would be to look at the referring URL and use the $q parameter...
Try this:
<?php
$refParts = parse_url($_SERVER["HTTP_REFERER"]);
$refVars = parse_str($refParts["PHP_URL_QUERY"]);
$refQ = tapestry_normalise($refVars["q"]);
?>
<p>
You are at <a href="/">Home</a> »
<?php if ($refQ): ?>
<a href="/search.php?q=<?php print tapestry_hyphenate($refQ); ?>"><?php print $refQ; ?></a> »
<?php else: ?>
<a href="/category/<?php print tapestry_hyphenate($mainProduct["category"]); ?>"><?php print $mainProduct["category"]; ?></a> »
<?php endif; ?>
<?php print $mainProduct["name"]; ?>
</p>
Fingers crossed!
Cheers,
David.
Hi David,
Ftp was down yesterday so couldn't test. Unfortunately, the breadcrumbs script doesn't work; when you search for something it takes a random category from one of the products, not the search term.
Thanks
Phil
Hi Phil,
I think that means that $_SERVER["HTTP_REFERER"] is not being populated on your server. Could you try changing the following section:
<?php
$refParts = parse_url($_SERVER["HTTP_REFERER"]);
$refVars = parse_str($refParts["PHP_URL_QUERY"]);
$refQ = tapestry_normalise($refVars["q"]);
?>
...just temporarily to:
<?php
$refParts = parse_url($_SERVER["HTTP_REFERER"]);
$refVars = parse_str($refParts["PHP_URL_QUERY"]);
$refQ = tapestry_normalise($refVars["q"]);
print_r($refParts);
?>
...and then let me know what is displayed (just infront of the breadcrumbs) - on one of the pages where you are expecting a search term to form part of the breadcrumbs - then undo the change...
Cheers,
David.
Here's what I get
Array ( [scheme] => http [host] => www.mydomain.co.uk [path] => / )
Hi Phil,
Thanks - I was expecting to see a query string there also, but it explains why it's not working at least!
Could you perhaps email me a link to the site with instructions for reaching a page that you would like to have a search term shown in the breadcrumbs and i'll take a look into it for you...
Cheers,
David.
I think breadcrumbs is a great idea and should be put in the official release. Did you solve the issue with the mod above as I would love to have breadcrumnbs,
I tried
<p>You are at <a href="/">Home</a> » <a href="/category/<?php print tapestry_hyphenate($mainProduct["category"]); ?>"><?php print $mainProduct["category"]; ?></a> » <?php print $mainProduct["name"]; ?></p>
in html/searchresults.php and various other places but the category and product is blank so I only see home > >. Does a file need to be included?
Would like the extra mod that implemented the search terms though if you completed this in the end.
Cheers, Steven
Hi Steven,
The code in your post would only work in html/product.php as this is the only script that creates the $mainProduct variable.
A generic version of the above, that should work within html/menu.php to create category breadcrumb would be as follows:
<div class='menu'>
<p>
<small>
You are at
<a href='<?php print $config_baseHREF; ?>'><?php print translate("Home"); ?></a>
<?php
$category = "";
if (!$category)
{
if ($parts[0]=="category")
{
$category = $parts[1];
}
}
if (!$category)
{
if ($product["products"][0]["category"])
{
$category = $product["products"][0]["category"];
}
}
if ($category)
{
print " » ";
if ($config_useRewrite)
{
$categoryHREF = $config_baseHREF."category/".tapestry_hyphenate($category)."/";
}
else
{
$categoryHREF = $config_baseHREF."search.php?q=category:".urlencode($category).":";
}
print "<a href='".$categoryHREF."'>".$category."</a>";
}
if ($product["products"][0]["name"])
{
print " » ";
print $product["products"][0]["name"];
}
elseif($q)
{
print " » ";
print "Searching for ".$q;
}
?>
</small>
</p>
</div>
Cheers,
David.
Thanks David, this would be great but unfortunately it doesn't work.
Clicking on a category shows the products and correctly displays home > Category. But the category URL points to:
http://example.com/category/insurance/search.php?q=category:insurance:
Also if I click to view a product, it displays home > Category. But the product name doesn't show.
Plus when I conduct a search it just displays: home.
Any way of correcting this?
Thanks very much, Steven :-)
Hi Steve,
I've corrected the above code so that the category link should be correct; and also added the product name to the end if on a product page (but not linked as it would only go to the page you're on).
For a normal (non category) search, what did you want the breadcrumb to display? Should be easy enough to add...
Cheers,
David.
Thanks, this works great. For a normal search displaying home > Searching for "search term" would be good.
I guess it would be a lot of work to display:
Home > category > product
on the product page when navigating through to products without searching. And display:
home > search term > product
on the product page when the user reached the product page via a search.
Cheers for your help!
Steven
Hi Steven,
I've modified the code above (just added an elseif at the end) to print "Searching for ...." on a normal search (or even a sub-search within a category)...
Cheers,
David.
Hi David,
You think that it is possible to obtain the same result with "merchant" and "brand" ?
Thank you for your answer.
Mick
Hello Mick,
Just to clarify, you would like to generate a breadcrumb based on the route taken to the product, so if it was from a merchant page then you would have Home > Merchant, whereas browsing by category you would have Home > Category etc.?
Cheers,
David.
Hi David,
Yes, it is exactly what I would like to obtain.
Home > Merchant > name of merchant
Home > Brand > name of brand
You think that it is possible ?
Thank you for your assistance.
Mick
Hello Mick,
I've tried to make this comprehensive, providing breadcrumbs on the merchant/category/brand index pages as well as the product page. Have a go with the following as completely replacement for html/menu.php
<div class='menu'>
<p>
<small>
<a href='<?php print $config_baseHREF; ?>'><?php print translate("Home"); ?></a>
<?php
$menuParts = explode("/",$_SERVER["PHP_SELF"]);
$menuPHPSelf = $menuParts[count($menuParts)-1];
$menuReferer = $_SERVER["HTTP_REFERER"];
switch($menuPHPSelf)
{
case "merchants.php":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"merchant/":"merchants.php");
$crumb1TEXT = "Merchant";
break;
case "categories.php":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"category/":"categories.php");
$crumb1TEXT = "Category";
break;
case "brands.php":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"brand/":"brand.php");
$crumb1TEXT = "Brand";
break;
case "search.php":
switch($parts[0])
{
case "merchant":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"merchant/":"merchants.php");
$crumb1TEXT = "Merchant";
break;
case "category":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"category/":"categories.php");
$crumb1TEXT = "Category";
break;
case "brand":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"brand/":"brands.php");
$crumb1TEXT = "Brand";
break;
}
break;
case "products.php":
if (strpos($menuReferer,$_SERVER["HTTP_HOST"])===FALSE) break;
if (strpos($menuReferer,"merchant"))
{
$crumb1HREF = $config_baseHREF.($config_useRewrite?"merchant/":"merchants.php");
$crumb1TEXT = "Merchant";
if (strpos($menuReferer,"q="))
{
$parts1 = parse_url($menuReferer);
$parts2 = explode("%3A",$parts1["query"]);
$crumb2HREF = $config_baseHREF."search.php?".$parts1["query"];
$crumb2TEXT = str_replace("+"," ",$parts2[1]);
}
else
{
$parts1 = explode("/",$menuReferer);
$crumb2HREF = $config_baseHREF."merchant/".$parts1[count($parts1)-2]."/";
$crumb2TEXT = tapestry_normalise($parts1[count($parts1)-2]);
}
}
elseif (strpos($menuReferer,"category"))
{
$crumb1HREF = $config_baseHREF.($config_useRewrite?"category/":"categories.php");
$crumb1TEXT = "Category";
if (strpos($menuReferer,"q="))
{
$parts1 = parse_url($menuReferer);
$parts2 = explode("%3A",$parts1["query"]);
$crumb2HREF = $config_baseHREF."search.php?".$parts1["query"];
$crumb2TEXT = str_replace("+"," ",$parts2[1]);
}
else
{
$parts1 = explode("/",$menuReferer);
$crumb2HREF = $config_baseHREF."category/".$parts1[count($parts1)-2]."/";
$crumb2TEXT = tapestry_normalise($parts1[count($parts1)-2]);
}
}
elseif (strpos($menuReferer,"brand"))
{
$crumb1HREF = $config_baseHREF.($config_useRewrite?"brand/":"brands.php");
$crumb1TEXT = "Brand";
if (strpos($menuReferer,"q="))
{
$parts1 = parse_url($menuReferer);
$parts2 = explode("%3A",$parts1["query"]);
$crumb2HREF = $config_baseHREF."search.php?".$parts1["query"];
$crumb2TEXT = str_replace("+"," ",$parts2[1]);
}
else
{
$parts1 = explode("/",$menuReferer);
$crumb2HREF = $config_baseHREF."brand/".$parts1[count($parts1)-2]."/";
$crumb2TEXT = tapestry_normalise($parts1[count($parts1)-2]);
}
}
break;
}
if ($crumb1HREF) print " » <a href='".$crumb1HREF."'>".$crumb1TEXT."</a>";
if ($crumb2HREF) print " » <a href='".$crumb2HREF."'>".$crumb2TEXT."</a>";
?>
</small>
</p>
</div>
I know that you have translated both titles and search engine friendly URLs, so in your instance, perform a Case Sensitive search and replace on the above for the following:
merchant.php > marchand.php
merchant/ > marchand/
Merchant > Marchand
...similar for Category and Brand of course.
Cheers,
David.
Hello David,
Thanks, your code functions perfectly.
But, to add Home > Product, I must just add the code suggested higher ?
I excuse myself, I had not indicated "Products" in my example.
Thanks very much, Mick
Hello Mick,
Do you mean to add a breadcrumb when there is no previous page (it works on the HTTP referer)?
Cheers,
David.
Hello David,
In fact, I would like a breadcrumb when the visitor is on the page of products.
For example, with your code, if the visitor is on merchant/, it obtains
Home > Merchant
there, on the Merchant page, it click on a link (product link), it should obtain : Home > Products
Currently, on the products/ page, it obtains only Home.
In the ideal, I would like to also obtain Homme > Review (for review/).
That would be more ergonomic for the visitor.
I do not know if I explain correctly ?
Thanks, Mick
Hello David,
I perhaps found a solution.
In fact, I added :
case "products.php":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"produits/":"products.php");
$crumb1TEXT = "Produits";
break;
case "reviews.php":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"review/":"reviews.php");
$crumb1TEXT = "Avis";
break;
in .htaccess
RewriteRule ^produits/$ products.php
RewriteRule ^reviews/$ reviews.php
...and that indicates correctly :
Home > Produits
Home > Avis
I have just a last question.
It is possible to add a condition on the reviews.php page ?
if id {...}
else {error message}
Currently, if the user goes directly on reviews.php without id, it obtains the form.
Thanks for your suggestion.
Mick
Hi Mick,
Look for the following code starting at line 89 of reviews.php:
if (isset($product)) require("html/product.php");
require("html/ratings.php");
..and restructure this as follows:
if (isset($product))
{
require("html/product.php");
require("html/ratings.php");
}
That should do the trick...
Cheers,
David.
Hello David,
I tested the comprehensive breadcrumb and it works. Wonder if that can be mod further.
Current:
Step 1. If I click on the merchant page it will list all the merchants, the breadcrumb will shows
Home > Merchant
Step 2. Then I click on let say Digicall, the page will show results of all products of Digicall. The breadcrumb will be
Home > Merchant
Home > Merchant > Digicall(Preferable)
Step 3. When I click on one of the product of that Digicall, the page will show that particular product page. The breadcrumb will be
Home > Merchant > Digicall
Home > Merchant > Digicall > Product Name (Preferable)
____________________________________
Could it be possible to have in Step 2, the breadcrumb shows
Home > Merchant > Digicall
And when click on Step 3, the breadcrumb shows
Home > Merchant > Digicall > Product Name
I supposed it will works for the brand and category as well.
thanks
jack
Hello Jack,
That can be done, the code is below but consider whether it is ideal or not (in your opinion) to have the primary page title appear in small text before the same text appears as the heading...
<div class='menu'>
<p>
<small>
<a href='<?php print $config_baseHREF; ?>'><?php print translate("Home"); ?></a>
<?php
$menuParts = explode("/",$_SERVER["PHP_SELF"]);
$menuPHPSelf = $menuParts[count($menuParts)-1];
$menuReferer = $_SERVER["HTTP_REFERER"];
switch($menuPHPSelf)
{
case "merchants.php":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"merchant/":"merchants.php");
$crumb1TEXT = "Merchant";
break;
case "categories.php":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"category/":"categories.php");
$crumb1TEXT = "Category";
break;
case "brands.php":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"brand/":"brand.php");
$crumb1TEXT = "Brand";
break;
case "search.php":
switch($parts[0])
{
case "merchant":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"merchant/":"merchants.php");
$crumb1TEXT = "Merchant";
$crumb2HREF = $config_baseHREF.($config_useRewrite?"merchant/"
.tapestry_hyphenate($parts[1])."/":"search.php?q=merchant:".urlencode($parts[1]).":");
$crumb2TEXT = $parts[1];
break;
case "category":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"category/":"categories.php");
$crumb1TEXT = "Category";
$crumb2HREF = $config_baseHREF.($config_useRewrite?"category/"
.tapestry_hyphenate($parts[1])."/":"search.php?q=category:".urlencode($parts[1]).":");
$crumb2TEXT = $parts[1];
break;
case "brand":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"brand/":"brands.php");
$crumb1TEXT = "Brand";
$crumb2HREF = $config_baseHREF.($config_useRewrite?"brand/"
.tapestry_hyphenate($parts[1])."/":"search.php?q=brand:".urlencode($parts[1]).":");
$crumb2TEXT = $parts[1];
break;
}
break;
case "products.php":
if (strpos($menuReferer,$_SERVER["HTTP_HOST"])===FALSE) break;
if (strpos($menuReferer,"merchant"))
{
$crumb1HREF = $config_baseHREF.($config_useRewrite?"merchant/":"merchants.php");
$crumb1TEXT = "Merchant";
if (strpos($menuReferer,"q="))
{
$parts1 = parse_url($menuReferer);
$parts2 = explode("%3A",$parts1["query"]);
$crumb2HREF = $config_baseHREF."search.php?".$parts1["query"];
$crumb2TEXT = str_replace("+"," ",$parts2[1]);
}
else
{
$parts1 = explode("/",$menuReferer);
$crumb2HREF = $config_baseHREF."merchant/".$parts1[count($parts1)-2]."/";
$crumb2TEXT = tapestry_normalise($parts1[count($parts1)-2]);
}
}
elseif (strpos($menuReferer,"category"))
{
$crumb1HREF = $config_baseHREF.($config_useRewrite?"category/":"categories.php");
$crumb1TEXT = "Category";
if (strpos($menuReferer,"q="))
{
$parts1 = parse_url($menuReferer);
$parts2 = explode("%3A",$parts1["query"]);
$crumb2HREF = $config_baseHREF."search.php?".$parts1["query"];
$crumb2TEXT = str_replace("+"," ",$parts2[1]);
}
else
{
$parts1 = explode("/",$menuReferer);
$crumb2HREF = $config_baseHREF."category/".$parts1[count($parts1)-2]."/";
$crumb2TEXT = tapestry_normalise($parts1[count($parts1)-2]);
}
}
elseif (strpos($menuReferer,"brand"))
{
$crumb1HREF = $config_baseHREF.($config_useRewrite?"brand/":"brands.php");
$crumb1TEXT = "Brand";
if (strpos($menuReferer,"q="))
{
$parts1 = parse_url($menuReferer);
$parts2 = explode("%3A",$parts1["query"]);
$crumb2HREF = $config_baseHREF."search.php?".$parts1["query"];
$crumb2TEXT = str_replace("+"," ",$parts2[1]);
}
else
{
$parts1 = explode("/",$menuReferer);
$crumb2HREF = $config_baseHREF."brand/".$parts1[count($parts1)-2]."/";
$crumb2TEXT = tapestry_normalise($parts1[count($parts1)-2]);
}
}
if ($crumb2HREF)
{
$crumb3HREF = $config_baseHREF.($config_useRewrite?"product/"
.tapestry_hyphenate($q).".html":"products.php?q=".urlencode($q));
$crumb3TEXT = $q;
}
break;
}
if ($crumb1HREF) print " » <a href='".$crumb1HREF."'>".$crumb1TEXT."</a>";
if ($crumb2HREF) print " » <a href='".$crumb2HREF."'>".$crumb2TEXT."</a>";
if ($crumb3HREF) print " » <a href='".$crumb3HREF."'>".$crumb3TEXT."</a>";
?>
</small>
</p>
</div>
Cheers,
David.
Hi David,
It works perfectly fine. I did some testing and notice that there are 2 things worth doing for completion.
1. When I am at Home and then click one of the mod featured product, it will brings me straight to that product. However the breadcrumb is still show Home. How can I show the breadcrumb as follow
Home > Product Name
At first I thought adding the Category as well but logically it will not work because from mainpage we click the particular product which may resides in multiple category. And also that product maybe available from 2 or more merchants. So the best would be
Home > Product Name.
2. When click review it also show Home. Would it be possible to have
Home > Review > Product Name
Wonder this can be made or to have another breadcrumb file just to do this.
This is a perfect breadcrumb. Many thanks.
cheers,
jack
Hello Jack,
Have a go with this...
<div class='menu'>
<p>
<small>
<a href='<?php print $config_baseHREF; ?>'><?php print translate("Home"); ?></a>
<?php
$menuParts = explode("/",$_SERVER["PHP_SELF"]);
$menuPHPSelf = $menuParts[count($menuParts)-1];
$menuReferer = $_SERVER["HTTP_REFERER"];
switch($menuPHPSelf)
{
case "merchants.php":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"merchant/":"merchants.php");
$crumb1TEXT = "Merchant";
break;
case "categories.php":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"category/":"categories.php");
$crumb1TEXT = "Category";
break;
case "brands.php":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"brand/":"brand.php");
$crumb1TEXT = "Brand";
break;
case "search.php":
switch($parts[0])
{
case "merchant":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"merchant/":"merchants.php");
$crumb1TEXT = "Merchant";
$crumb2HREF = $config_baseHREF.($config_useRewrite?"merchant/"
.tapestry_hyphenate($parts[1])."/":"search.php?q=merchant:".urlencode($parts[1]).":");
$crumb2TEXT = $parts[1];
break;
case "category":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"category/":"categories.php");
$crumb1TEXT = "Category";
$crumb2HREF = $config_baseHREF.($config_useRewrite?"cateogry/"
.tapestry_hyphenate($parts[1])."/":"search.php?q=category:".urlencode($parts[1]).":");
$crumb2TEXT = $parts[1];
break;
case "brand":
$crumb1HREF = $config_baseHREF.($config_useRewrite?"brand/":"brands.php");
$crumb1TEXT = "Brand";
$crumb2HREF = $config_baseHREF.($config_useRewrite?"brand/"
.tapestry_hyphenate($parts[1])."/":"search.php?q=brand:".urlencode($parts[1]).":");
$crumb2TEXT = $parts[1];
break;
}
break;
case "reviews.php":
print " » Review";
$crumb1HREF = $config_baseHREF.($config_useRewrite?"product/"
.tapestry_hyphenate($q).".html":"products.php?q=".urlencode($q));
$crumb1TEXT = $q;
break;
case "products.php":
if (strpos($menuReferer,$_SERVER["HTTP_HOST"])===FALSE) break;
if (strpos($menuReferer,"merchant"))
{
$crumb1HREF = $config_baseHREF.($config_useRewrite?"merchant/":"merchants.php");
$crumb1TEXT = "Merchant";
if (strpos($menuReferer,"q="))
{
$parts1 = parse_url($menuReferer);
$parts2 = explode("%3A",$parts1["query"]);
$crumb2HREF = $config_baseHREF."search.php?".$parts1["query"];
$crumb2TEXT = str_replace("+"," ",$parts2[1]);
}
else
{
$parts1 = explode("/",$menuReferer);
$crumb2HREF = $config_baseHREF."merchant/".$parts1[count($parts1)-2]."/";
$crumb2TEXT = tapestry_normalise($parts1[count($parts1)-2]);
}
}
elseif (strpos($menuReferer,"category"))
{
$crumb1HREF = $config_baseHREF.($config_useRewrite?"category/":"categories.php");
$crumb1TEXT = "Category";
if (strpos($menuReferer,"q="))
{
$parts1 = parse_url($menuReferer);
$parts2 = explode("%3A",$parts1["query"]);
$crumb2HREF = $config_baseHREF."search.php?".$parts1["query"];
$crumb2TEXT = str_replace("+"," ",$parts2[1]);
}
else
{
$parts1 = explode("/",$menuReferer);
$crumb2HREF = $config_baseHREF."category/".$parts1[count($parts1)-2]."/";
$crumb2TEXT = tapestry_normalise($parts1[count($parts1)-2]);
}
}
elseif (strpos($menuReferer,"brand"))
{
$crumb1HREF = $config_baseHREF.($config_useRewrite?"brand/":"brands.php");
$crumb1TEXT = "Brand";
if (strpos($menuReferer,"q="))
{
$parts1 = parse_url($menuReferer);
$parts2 = explode("%3A",$parts1["query"]);
$crumb2HREF = $config_baseHREF."search.php?".$parts1["query"];
$crumb2TEXT = str_replace("+"," ",$parts2[1]);
}
else
{
$parts1 = explode("/",$menuReferer);
$crumb2HREF = $config_baseHREF."brand/".$parts1[count($parts1)-2]."/";
$crumb2TEXT = tapestry_normalise($parts1[count($parts1)-2]);
}
}
if ($crumb2HREF)
{
$crumb3HREF = $config_baseHREF.($config_useRewrite?"product/"
.tapestry_hyphenate($q).".html":"products.php?q=".urlencode($q));
$crumb3TEXT = $q;
}
else
{
$crumb1HREF = $config_baseHREF.($config_useRewrite?"product/"
.tapestry_hyphenate($q).".html":"products.php?q=".urlencode($q));
$crumb1TEXT = $q;
}
break;
}
if ($crumb1HREF) print " » <a href='".$crumb1HREF."'>".$crumb1TEXT."</a>";
if ($crumb2HREF) print " » <a href='".$crumb2HREF."'>".$crumb2TEXT."</a>";
if ($crumb3HREF) print " » <a href='".$crumb3HREF."'>".$crumb3TEXT."</a>";
?>
</small>
</p>
</div>
Cheers,
David.
Hello David,
I have tested the latest mod and it is perfect. Superb job. Well done.
Thank you very much.
Cheers,
jack
Hello David,
It is really a very useful code !
But, it would be possible to improve a last point ?
I would like to obtain the menu produces like this (cf. Reviews) :
Home > Produit > Name of Produit
You think that it is possible ?
Thank you for your assistance.
Mick
Hello Mick,
You could do that by modifying this section, near the end of the code:
if ($crumb2HREF)
{
$crumb3HREF = $config_baseHREF.($config_useRewrite?"product/"
.tapestry_hyphenate($q).".html":"products.php?q=".urlencode($q));
$crumb3TEXT = $q;
}
else
{
$crumb1HREF = $config_baseHREF.($config_useRewrite?"product/"
.tapestry_hyphenate($q).".html":"products.php?q=".urlencode($q));
$crumb1TEXT = $q;
}
...as follows:
if ($crumb2HREF)
{
$crumb3HREF = $config_baseHREF.($config_useRewrite?"product/"
.tapestry_hyphenate($q).".html":"products.php?q=".urlencode($q));
$crumb3TEXT = $q;
}
else
{
print " » Product";
$crumb1HREF = $config_baseHREF.($config_useRewrite?"product/"
.tapestry_hyphenate($q).".html":"products.php?q=".urlencode($q));
$crumb1TEXT = $q;
}
Hope this helps!
Cheers,
David.
Hello David,
Thanks very much, Works great ! :)
Mick
Me again :)
I have the categoryFilter[] and merchantFilter[] side bar mod, how can i get this working with it?
Thanks
Steve
Hi Steve,
The breadcrumb code above doesn't rely on filters as such but always refers to a category in context (either browsing by category from the Category A-Z page, or with reference to the specific category that a product is in).
If you have already tried to implement any of the above but it's not working as expected perhaps if you could let me know any example URL showing the problem (I'll remove before publishing your reply) I'll check it out for you...
Thanks!
David.
--
PriceTapestry.com
I've had a play around with it.
Got some of it working. Needs to spend some more time playing. I'll pop back on if I could do with a hand.
Thanks :)
So i'm back playing with the breadcrumbs and it's been a while heh.
I've got it working pretty much how i want it on the search page, my navigation is basically using the side bar filters and each category/subcategory/merchant/brand is placed into the breadcrumb trail.
I'd like to be able to make it so that on the products page i can have:
Home > categoryname > subcategoryname > productname
Is there a way to pass this information to the breadcrumbs script? I've tried using: $product["products"][0]["category"] but nothing shows.
Any help as always is much appreciated :)
Thanks You
Steve
Hello Steve,
$product["products"][0]["category"] should work. If you wanted to add debug code to see all available variables in the first product record, you can add the following at a stuiable juncture (e.g. top of your breadcrumb code)...
<?php
print_r($product["products"][0]);
?>
But what could also be the case when products are compared is that `category` and `subcategory` (or whatever variable name you're using) is that those fields are not populated in every product record. In this case, what you can do is foreach through the $product["products"] array and look for any populated values, for example:
$category = "";
$subcategory = "";
foreach($product["products"] as $p)
{
if ($p["category"]) $category = $p["category"];
if ($p["subcategory"]) $subcategory = $p["subcategory"];
}
...and then coming out of the above code $category and $subcategory will be populated if found from any record...
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Great stuff. Very helpful! Seem to be getting somewhere now.
Thanks
Steve
Hi Phil,
Just tapestry_hyphenate() around $mainProduct["category"] - for example:
<p>You are at <a href="/">Home</a> » <a href="/category/<?php print tapestry_hyphenate($mainProduct["category"]); ?>"><?php print $mainProduct["category"]; ?></a> » <?php print $mainProduct["name"]; ?></p>
Cheers,
David.