Get Category Informations by ID
Sometimes it is usefull to access category informations by its ID.
You can add those functions in functions.php :
- pxSingleCatDescriptionById : shows the description of the category
- pxSingleCatPathById : shows the path (relative or absolute) of the category
Obtenir des informations sur une catégorie à partir de son identifiant
Il est parfois utile d'obtenir des informations sur une catégorie donnée à partir de son identifiant.
Voici deux fonctions permettant de le faire, à ajouter dans functions.php :
- pxSingleCatDescriptionById : fournit la description de la catégorie
- pxSingleCatPathById : fournit le chemin (relatif ou absolu) de la catégorie
/**
Display the description of the current category.
@proto function pxSingleCatDescription
@param string identifier
@param string s Substitution string ('%s')
@param int limit maximum length of the output text (0)
*/
function pxSingleCatDescriptionById
($identifier,
$s=
'%s',
$limit=
0)
{
$c=
$GLOBALS['_PX_render']['m']->
getCategory($identifier);
if (null !==
$c) {
if ($limit) {
$text =
substr(textParseContent
($c->
f('category_description'),
'text'),
0,
$limit);
echo sprintf($s,
$text);
} else {
echo textParseContent
($c->
f('category_description'));
}
}
}
/**
Display the category path
@proto function pxSingleCatPath
@param string identifier
@param string s Substitution string ('%s')
*/
function pxSingleCatPathById
($identifier,
$s =
'%s')
{
global $_PX_website_config,
$_PX_config;
$c=
$GLOBALS['_PX_render']['m']->
getCategory($identifier);
if (null !==
$c) {
$path =
$_PX_website_config['rel_url'];
if ($_PX_config['url_format'] ==
'simple') {
$path .=
'/index.php?';
}
$path .=
$c->
f('category_path');
echo sprintf($s,
$path);
}
}
?>