You are here:  » Show category in search result

Support Forum



Show category in search result

Submitted by cq on Fri, 2008-09-26 09:23 in

Hi David,

How can i display the category in search results for each product listed.

thanks
jack

Submitted by support on Fri, 2008-09-26 11:08

Hello Jack,

Within the main loop within html/searchresults.php, the category will be in the variable $product["category"]; so you could display this as a link to that category's search results after the description by replacing the following code (line 20):

<p><?php print substr($product["description"],0,250); ?></p>

With:

<p><?php print substr($product["description"],0,250); ?></p>
<?php
  if ($config_useRewrite)
  {
    $href = $config_baseHREF."category/".tapestry_hyphenate(".$product["category"].")."/";
  }
  else
  {
    $href = $config_baseHREF."search.php?q=category:".urlencode($product["category"]).":";
  }
  print "<p>Category: <a href='".$href."'>".$product["category"]."</a></p>";
?>

Cheers,
David.

Submitted by cq on Fri, 2008-09-26 15:42

Hello David,

I got a blank results but the banner did show the total products.

How to solve it.

thanks
jack

Submitted by support on Fri, 2008-09-26 17:16

Hello Jack,

This modification should not have changed the existing appearance at all - could you email me your modified html/searchresults.php and i'll check it over for you...

Cheers,
David.

Submitted by cq on Sat, 2008-09-27 02:30

Hello David,

I got error message as below

Parse error: syntax error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/xxxx/public_html/xxxxx/html/searchresults.php on line 26

thanks
jack

Submitted by support on Sat, 2008-09-27 08:10

Hi,

Could you email the file to me again and i'll check it out for you...

Cheers,
David.

Submitted by cq on Sat, 2008-09-27 08:36

Hi David,

I have email to you.

thanks
jack

Submitted by cq on Sat, 2008-09-27 08:54

Hi David,

I got it working. Very inspiring. I added merchant and brand as well. Thank you very much.

Wonder if i can include review as well. Is the same just change to review in the script.

thanks
jack

Submitted by support on Sat, 2008-09-27 10:28

Hello Jack,

Very similar - try this code for a review link:

  if ($config_useRewrite)
  {
    $href = $config_baseHREF."review/".tapestry_hyphenate($product["name"])."/";
  }
  else
  {
    $href = $config_baseHREF."reviews.php?q=".urlencode($product["name"]);
  }
  print "<p><a href='".$href."'>Review This Product</a></p>";

Cheers,
David.

Submitted by cq on Sun, 2008-09-28 07:04

Hi David,

The review product doesn't work. When click it goes back to main page. How to get it right.

thanks
jack

Submitted by cq on Sun, 2008-09-28 07:39

Hello David,

Is this corrent to include the rating.How can i make it to look like Rating: ***** or if there is no rating, then it diplay Rating: None or just blank.

<?php
 
if ($product["rating"]) print tapestry_stars($product["rating"],""); 
?>

thanks
jack

Submitted by support on Mon, 2008-09-29 03:27

Hello Jack,

That code is fine wherever the $product variable contains a product record (like in the main loop in html/searchresults.php.

To display "None" if there is no rating; use:

<?php
 
if ($product["rating"])
 {
   print 
tapestry_stars($product["rating"],"");
 }
 else
 {
   print 
"None";
 }
?>

Cheers,
David.

Submitted by cq on Mon, 2008-09-29 04:05

Hi David,

Thanks. I added the .html to the below scripts and i working now

<?php
if ($config_useRewrite)
  {
    
$href $config_baseHREF."review/".tapestry_hyphenate($product["name"]).".html";
  }
  else
  {
    
$href $config_baseHREF."reviews.php?q=".urlencode($product["name"]).".html";
  }
  print 
"<p>Product Review: <a href='".$href."'>Add Review</a></p>";
?>

<?php
 
print translate("Ratings: "); 
?>

<?php
 
if ($product["rating"])
 {
   print 
tapestry_stars($product["rating"],"");
 }
 else
 {
   print 
"None";
 }
?>

I am trying to get the output look like below but couldn't figure out. Unsuccessful.

Product review: Read Reviews (2)| Add Reviews | Rating: **

How can i get the output like the above.

thanks
jack

Submitted by support on Mon, 2008-09-29 07:51

Hello Jack,

It will be the P tags separating everything. Try something like this:

<?php
  
print "<p>";
  print 
"Product review: ";
  if (
$config_useRewrite)
  {
    
$href $config_baseHREF."review/".tapestry_hyphenate($product["name"]).".html";
  }
  else
  {
    
$href $config_baseHREF."reviews.php?q=".urlencode($product["name"]).".html";
  }
  print 
"<a href='".$href."'>Read Reviews</a> (".$product["reviews"].")";
  print 
" | ";
  print 
"<a href='".$href."'>Add Reviews</a>";
  print 
" | ";
  print 
"Rating: "
  if (
$product["rating"])
  {
    print 
tapestry_stars($product["rating"],"");
  }
  else
  {
    print 
"None";
  }
  print 
"</p>";
?>

Cheers,
David.

Submitted by cq on Mon, 2008-09-29 09:57

Hello David,

Works fine. Thank you so much.

cheers,
jack