You are here:  » Category banner

Support Forum



Category banner

Submitted by henk on Fri, 2008-03-07 18:30 in

Hi,

is it possible to have a banner on every category, based on the category.

thx
HEnk

Submitted by support on Sat, 2008-03-08 08:01

Hi Henk,

The category pages are created by search.php in response to a query ($q) of the format:

category:Widgets:

Throughout that page, and on any used HTML module, you can look at the $parts[0] variable to see if it contains "category". If it does, the category name is in $parts[1]. For example, if you wanted to include your banner in html/header.php, you might use something like this:

<?php
  if ($parts[0] == "category")
  {
    // print your banner code here, using $parts[1] as the category name
  }
?>

Hope this helps,
Cheers,
David.

Submitted by henk on Thu, 2008-03-13 19:34

Hi it worked, is it also possible with search words.

HEnk

Submitted by support on Thu, 2008-03-13 19:36

Hi Henk,

Sure - just use an elseif, and check that $parts[1] is empty, which means that $parts[0] is a search word:

<?php
  
if ($parts[0] == "category")
  {
    
// print your banner code here, using $parts[1] as the category name
  
}
  elseif(!
$parts[1])
  {
    
// print your banner code here, using $parts[0] as the search word
  
}
?>

Cheers,
David.

Submitted by henk on Fri, 2008-03-14 18:56

Great,

And can it be done with a list of words ?

Thx
Henk

Submitted by support on Fri, 2008-03-14 19:18

Hi Henk,

$parts[0] would contain the whole search string, so "word1 word2" if there were 2 words in the search. You can either use this in whole, or if you want to split it up into individual words, try something like this:

<?php
  
if ($parts[0] == "category")
  {
    
// print your banner code here, using $parts[1] as the category name
  
}
  elseif(!
$parts[1])
  {
    
$words explode(" ",$parts[0]);
    foreach(
$words as $word)
    {
      
// print your banner code here, using $word as one of the search words
    
}
  }
?>

Cheers,
David.

Submitted by atlanta1 on Thu, 2008-08-21 09:29

Hi David and All

I'm trying to create some unique text at the top of every "/category/..../" page before searchresults.php kicks in.

Am I looking at the correct thread?

I'd also like to do the same for "/brand/..../" too at some point.

I've tried implementing it using this code - without success.

I think the problem is to do with this line.... which I don't understand

// print your banner code here, using $parts[1] as the category name

Can you give me an example of what it should look like?

Thank you

Submitted by support on Thu, 2008-08-21 10:58

Hi,

Here's an example with some output at those points, as well as adding a section for /brand/...

<?php
  
if ($parts[0] == "category")
  {
    
// print your banner code here, using $parts[1] as the category name
    
print "<p>You are browsing ".$parts[1]." products...</p>";
  }
  elseif (
$parts[0] == "brand")
  {
    
// print your banner code here, using $parts[1] as the brand name
    
print "<p>You are browsing ".$parts[1]." products...</p>";
  }
  elseif(!
$parts[1])
  {
    
$words explode(" ",$parts[0]);
    foreach(
$words as $word)
    {
      
// print your banner code here, using $word as one of the search words
      
print "<p>You searched for ".$word."</p>";
    }
  }
?>

The latter part will display a paragraph per word in the search term (if not a category search), which may not be what you want in which case just delete this section.

I think the original intention was to actually call in banners (advertising) from a remote ad server where the category or keywords are used in the call in order to bring back relevant adverts; so in that case the code would be output more than a simple text string, it would need to generate the relevant HTML (normally as provided by the affiliate/advertising network) in order to call in the banner.

If this isn't what you're trying to do let me know and I'll try and offer further advice...!

Cheers,
David.

Submitted by atlanta1 on Thu, 2008-08-21 11:52

Hi David

Very quick response - thank you!

What I would like to do is call a file with unique text relevent to the category.

OK - So for example

Say we have a category "TVs" - I would like to display a few lines of text about TV's above the search results

Then "brand" say "Humax" - display some text and links relevent to Humax.

Obviously, I'm aware I'll need to create these files seperately.

I wondered if this bit of code would be suitable for this purpose.

Cheers

Submitted by support on Thu, 2008-08-21 12:08

Hi,

Sure - i've recommended just such a technique of using files to include unique content in several different ways in Price Tapestry. In this case, I would recommend creating the following directory structure:

content/category/
content/brand/

...and within the category and brand folders, create files with the exact name (including spaces) of each category or brand for which you want to add additional content; and then use code along the lines of:

<?php
  
if ($parts[0]=="category" || $parts[0]=="brand")
  {
    
$filename "content/".$parts[0]."/".$parts[1];
    if (
file_exists($filename))
    {
      require(
$filename);
    }
  }
?>

The files can contain as much text / HTML / links etc. as you like!

Hope this helps!

Cheers,
David.

Submitted by atlanta1 on Thu, 2008-08-21 12:35

Thanks again David.

Submitted by support on Thu, 2008-08-21 12:42

Hi,

The code I posted doesn't look for ".txt" on the end. If you want to have .txt to make it easier for you to edit files etc., then simply change the code as follows:

<?php
  
if ($parts[0]=="category" || $parts[0]=="brand")
  {
    
$filename "content/".$parts[0]."/".$parts[1].".txt";
    if (
file_exists($filename))
    {
      require(
$filename);
    }
  }
?>

That should do the trick!

Cheers,
David.

Submitted by atlanta1 on Thu, 2008-08-21 13:00

Bingo!

Thank you so much!