View Full Version : Display Category Name
Hi,
I am working on SEO URL's and need a bit of direction getting the category name.
In the class.shopcore.php file, the category ID is shown using $iCategoryId, how do I get the actual category name instead of the id?
To look something like this...
$sReturn .= 'category/'.$CategoryName;
Thanks in advance.
Simon.
Hi,
I have been watching this thread in the hope that someone would post something clever in reply to your question, as no one has, I suppose I will have to kick this off in the hope that someone can improve on the code below (there must be a a one liner to do this!)
$c=$_GET['c'];
$oCategoryParams= new stdClass();
$oCategoryParams->aCategoryIds[]= $c;
// get the categories
$oCategory= new api_category();
$aCategories= $oCategory->getCategory($oCategoryParams);
echo $aCategories[$c]->sName;
The above should echo the category name of the current selection,
I use something similar to create a link to relevant ebay listings for musical instruments at the bottom of
http://pricecompareuk.com/Musical-Instruments
Hi,
Thanks for your reply, ill give it a go!
Simon
Hi,
I have had no joy in getting the category to show. Maybe someone will eventually stumble upon this thread and give me some more direction.
Thanks for your help.
Simon.
Hi Simon,
If you only have the category ID available on a given page you will have to do some kind of lookup to get the category name. The code Amcho has given should do the trick. What problems are you having with Amcho's code? Echo the results of each step and make sure you are passing and receiving what you think you are.
IntroSites
03-07-08, 23:54
if you are talking about "function buildUrl" you could always send the category name from the page where you call the function
Hi,
Ok lets get this sorted!
I have placed this code as follows in class.shopcore.php
case T_CATEGORY:
$c=$_GET['c'];
$oCategoryParams= new stdClass();
$oCategoryParams->aCategoryIds[]= $c;
// get the categories
$oCategory= new api_category();
$aCategories= $oCategory->getCategory($oCategoryParams);
//echo $aCategories[$c]->sName;
$sReturn .= 'category('.$aCategories[$c]->sName.')';
if(is_numeric($iMerchantId)) $sReturn .= '('.$iMerchantId.')';
if(strlen($sRefineByVals)>0) $sReturn .= '('.$sRefineByVals.')';
$sReturn .= '.html';
break;
Am I on the right track here guys?
Thanks,
Simon