Thanks for the info. I needed a way to run code for a particular category only and your post was my starting point.
The reason I need to do this is for Google Remarketing. I was surprised that no-one else has posted about this on the Virtuemart forum so I thought I would let you know how I got on..
To make Google Remarketing work, Google needs to know if a user has visited a specific part of your website (the Gardening section in my case). I added the following code to the end of the virtuemart.php file (found in components/com_virtuemart). The code I bodged together finds the parent category id. You can then use an if statement to run code only if the parent id is the one you are interested in. The code also uses the current category id instead of the parent category id if the parent category id is 0 (if you are already in a top level category).
Note I have included the code just before and after my code in the following snippet so that you can see where it goes.
// Set debug option on/off
if (vmShouldDebug()) { /*@MWM1: Log/Debug enhancements */
$end = utime();
$runtime = $end - $start;
include( PAGEPATH . "shop.debug.php" );
}
/* Get Parent Cat ID for Google Remarketing*/
$db = & JFactory::getDBO();
$q = "SELECT category_parent_id FROM #__vm_category_xref WHERE category_child_id = ".$category_id;
$db->setQuery($q);
$parentIDList = $db->loadObjectList();
$parentID=$parentIDList[0]->category_parent_id;
if($parentID==0){
$parentID = $category_id;
}
/*echo $parentID;*/ //uncomment this to show the parentID on your page while you check it works
if($parentID ==3801){ //3801 is my gardening top level category, you need to change this for your site
?><!-- Google Code for Gardening Tools Remarketing List -->
// replace this line with the code from google, or other code you want to use
<?php
}
/* End Google Parent Cat Id...*/
}
$vm_mainframe->close();
?>
You can see this working here:
http://www.bannerfieldtools.com/gardening. If I haven't run out of money you should see some gardening related ads on your travels (you can turn this off here:
http://www.google.com/ads/preferences)
I would really appreciate it if someone could help me tidy this code up a bit. All suggestions welcome. Also, next step is to load in a file with the google code only if in the right category, so any advice on that also welcome.