You are here:  » Display Default Heading and Description For Category and Brand Pages


Display Default Heading and Description For Category and Brand Pages

Submitted by bat on Wed, 2022-01-12 14:35 in

Hi David,
Is it possible to display a default H1 heading tag and a description on a category or brand page with that respective category/brand name pulled in?

I have descriptions set up in the backend for manually adding in brand and category descriptions, but having something auto-added in would suffice until I get round to filling them all out manually. My manual descriptions would be in addition to these auto-default ones, not instead of.

i.e. if it was a 'mobile phones' category page, then the results page would have a H1 saying "Buy Mobile Phones' in the UK" and then the description would be something where the category name could be pulled in..... "Looking for Mobile Phones? You've come to the right place!"

Thanks!

Submitted by support on Thu, 2022-01-13 11:12

Hi,

Sure - as the pages are generated by the search code, to add an H1 heading to the top
of page 1 (default sort and assuming rewrite) edit html/searchresults.php and add the following new PHP section to the top of the script;

<?php
  
if (isset($parts[1]) && $rewrite && ($page==1))
  {
    print 
"<div class='row'><div class='small-12 columns'>";
    print 
"<h1>Buy ".$parts[1]." In The UK</h1>";
    print 
"</div></div>";
  }
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by bat on Thu, 2022-01-13 12:50

Thanks, this is great!
Is there a way to specify different based on whether it's a category, merchant or brand page? Also, to use the last category name only when pulling it into the H1 (I'm using hierarchy category setup) as it's currently pulling in "Buy maincat/subcat in the UK"

Submitted by support on Thu, 2022-01-13 15:03

Hi,

Have a go with something like;

<?php
  
if (isset($parts[1]) && $rewrite && ($page==1))
  {
    switch(
$parts[0])
    {
      case 
"merchant"$h1 = array("Before Merchant",$parts[1],"After Merchant"); break;
      case 
"category"$h1 = array("Before Category",$nodeInfo["name"],"After Category"); break;
      case 
"brand"$h1 = array("Before Brand",$parts[1],"After Brand"); break;
    }
    print 
"<div class='row'><div class='small-12 columns'>";
    print 
"<h1>".implode(" ",$h1)."</h1>";
    print 
"</div></div>";
  }
?>

Cheers,
David.
--
PriceTapestry.com

Submitted by bat on Thu, 2022-01-13 15:55

Ah, perfecto! Thank you, David!