Category link in breadcrumbs
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.
--
Developer, Price Tapestry
For unrelated PHP, MySQL or Affiliate Marketing tech help please post your questions on my personal forum
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.
--
Developer, Price Tapestry
For unrelated PHP, MySQL or Affiliate Marketing tech help please post your questions on my personal forum
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.
--
Developer, Price Tapestry
For unrelated PHP, MySQL or Affiliate Marketing tech help please post your questions on my personal forum
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.
--
Developer, Price Tapestry
For unrelated PHP, MySQL or Affiliate Marketing tech help please post your questions on my personal forum
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.
--
Developer, Price Tapestry
For unrelated PHP, MySQL or Affiliate Marketing tech help please post your questions on my personal forum
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.
--
Developer, Price Tapestry
For unrelated PHP, MySQL or Affiliate Marketing tech help please post your questions on my personal forum
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.
--
Developer, Price Tapestry
For unrelated PHP, MySQL or Affiliate Marketing tech help please post your questions on my personal forum