PDA

View Full Version : Display Category Name


crounauer
18-06-08, 17:27
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.

amcho
23-06-08, 18:39
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

crounauer
02-07-08, 16:31
Hi,

Thanks for your reply, ill give it a go!

Simon

crounauer
03-07-08, 22:04
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.

authcode
03-07-08, 23:06
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

crounauer
04-07-08, 17:20
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