Get Article Informations by ID
Sometimes it is usefull to access article informations by its ID.
You can add those functions in functions.php :
- pxArtDescriptionById : shows the description of the article
- pxArtPathById : shows the path (relative or absolute) of the article
Obtenir des informations sur un article à partir de son identifiant
Il est parfois utile d'obtenir des informations sur un article donné à partir de son identifiant.
Voici deux fonctions permettant de le faire, à ajouter dans functions.php :
- pxArtDescriptionById : fournit la description de l'article
- pxArtPathById : fournit le chemin (relatif ou absolu) de l'article
/**
Display the description of the article.
@proto function pxArtDescriptionById
@param string identifier
@param string s Substitution string ('%s')
@param int limit maximum length of the output text (0)
*/
function pxArtDescriptionById
($identifier,
$s=
'%s',
$limit=
0)
{
$a=
$GLOBALS['_PX_render']['m']->
getArticle($identifier,
1);
if (null !==
$a) {
if ($limit) {
$text =
substr(textParseContent
($a->
f('description'),
'text'),
0,
$limit);
echo sprintf($s,
$text);
} else {
echo textParseContent
($a->
f('description'));
}
}
}
/**
Display the path to the article.
@proto function pxArtPath
@param string type 'full' give path with http:// ('relative')
*/
function pxArtPathById
($identifier,
$type =
'relative')
{
global $_PX_website_config,
$_PX_config;
$a=
$GLOBALS['_PX_render']['m']->
getArticle($identifier,
1);
if (null !==
$a) {
$s =
($_PX_website_config['secure']) ?
's' :
'';
switch ($type) {
case 'full' :
$path =
'http'.
$s.
'://'.
$_PX_website_config['domain'].
$_PX_website_config['rel_url'];
break;
default :
$path =
$_PX_website_config['rel_url'];
break;
}
if ($_PX_config['url_format'] ==
'simple') {
$path .=
'/index.php?';
}
$path .=
$a->
getPath();
echo $path;
}
}