Get content ID from given page alias

Sometimes you need the page alias AND the content id. All you need is a tiny UserDefined Tag (UDT).

Create a new UDT "getpageid" and copy&paste the following code:

if( !isset($params['alias']) ) return;
$gCms = cmsms();
$contentops =& 
$gCms->GetContentOperations();
$assign = $params["assign"];
$id = $contentops->GetPageIDFromAlias( $params['alias'] );
if (isset($params["assign"])){
  $smarty->assign($assign,$id);
}else{
  echo $id;
}

Now we can retreive the content_id like this:

{getpageid alias="home" assign="pageid"}

We have optionally assigned the value to the var "pageid". Therefore you can call it whereever you want with {$pageid}.

Comments