RSS

Newsletter

The CodeKarate Newsletter is the best way for technical ninjas to keep their swords sharpened. Don't worry, we won't flood your inbox and your email address will always remain private.
Back to Top

Unique Ubercart catalog page classes

If you have an Ubercart E-commerce website built with Drupal 6 and need to need theme different catalog pages differently, you are not alone. I recently ran into a situation that required links to be a different color on a specific catalog page. That part was fairly easy as there were unique body classes available for each page (I was using a Zen subtheme). However, it was not intuitive getting all the children terms of that catalog page to show up the same way.

Turns out there is a fairly easy solution to add an additional body class to the theme that will point to the parent taxonomy item. Note: This was only tested with a simple taxonomy structure, no guarantees that it will work if your taxonomy structure is overly complicated.

Just add this to your theme:

function MYTHEME_preprocess_page(&$vars) {
  $arg0 = arg(0);
  $arg1 = arg(1);
  if (isset($arg0) && $arg0 == 'catalog' && isset($arg1) && is_numeric($arg1)) {
    $parents = taxonomy_get_parents($arg1);
    if (!empty($parents) && $parent = array_pop($parents)) {
      $vars['body_classes'] .= ' catalog-parent-' . $parent->tid;
    }
  }
}

All the above does is add an additional class on the body html tag that looks something like "catalog-parent-[TID]" where the [TID] is replaced with the taxonomy term id of the parent taxonomy term. For example, assume you had a taxonomy structure for your store catalog that looked like this:

- Shirts (tid = 1)
-- T-Shirts
-- Dress Shirts
- Boots (tid = 2)
-- Work Boots
-- Western Boots

If you now navigate to the "T-Shirts" catalog page, there will be a unique class on the body tag of your HTML with a class name of "catalog-parent-1". You could use this to theme the page differently in your CSS code.

Discussions

1
santa (not verified)

great blog

great blog

2
paper shredding nyc (not verified)

Business models across the

Business models across the world also continue to change drastically with the advent of eCommerce and this change is not just restricted to USA. Other countries are also contributing to the growth of eCommerce. For example, the United Kingdom has the biggest e-commerce market in the world when measured by the amount spent per capita, even higher than the USA. Thanks.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <h3> <blockquote> <img>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <css>, <html>, <php>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <mysql>, <python>, <ruby>. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.