Support forum login

©2006-2008 IAAI Software

Contact Us

Category link in breadcrumbs

Submitted by philh on Sun, 2008-06-15 16:40.

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

Submitted by dmorison on Sun, 2008-06-15 16:42.

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

Submitted by philh on Mon, 2008-06-16 20:10.

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

Submitted by philh on Mon, 2008-06-16 20:11.

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!

Submitted by philh on Mon, 2008-06-16 20:35.

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

Submitted by philh on Mon, 2008-06-16 20:39.

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 )

Submitted by dmorison on Tue, 2008-06-17 08:18.

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

Submitted by philh on Wed, 2008-06-18 19:26.

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

Submitted by dmorison on Thu, 2008-06-19 07:35.

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

Submitted by philh on Thu, 2008-06-19 19:01.

Here's what I get

Array ( [scheme] => http [host] => www.mydomain.co.uk [path] => / )

Submitted by dmorison on Fri, 2008-06-20 08:21.

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

Submitted by steve on Fri, 2008-09-26 15:53.

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

Submitted by dmorison on Fri, 2008-09-26 17:33.

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 " &raquo; ";
        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 " &raquo; ";
        print $product["products"][0]["name"];
      }
      elseif($q)
      {
        print " &raquo; ";
        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

Submitted by steve on Fri, 2008-09-26 21:07.

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 :-)

Submitted by dmorison on Sat, 2008-09-27 08:01.

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

Submitted by steve on Sat, 2008-09-27 13:13.

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

Submitted by dmorison on Sat, 2008-09-27 19:06.

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