General
Getting & Giving Support
Administration
Design
- Tut. - Layouts and Themes
- Tut. - Navigation cookbook
- Tut. - How To section
Reference Material
Plugin Development
- Tut. - Writing a plugin
- Ref. - List of Events
- Ref. - Enabling cron jobs
- Ref. - PHPDoc
Core Development
- Ref. - PHPDoc
Press information
Wolf CMS books section
urlById()
This function1) makes it possible always to produce a correct and current url to the page despite it possibly having moved from its original position in the page hierarchy. It does this by using the page's id.2)
See also: linkById()
Usage
<?php echo Page::urlById(3); ?>
where “3” in the example above is the “id” of the targetted page. It will produce the corresponding URL, e.g. http://www.example.com/about_us
To find out what the ID of a given page is, either look on the “metadata” tab, or hover above the page's title or icon in the main admin page listing, where the ID will appear as a tooltip.
Using a variable for the ID
Using a simple variable for the ID will not pass the filter test set by the urlById() function. In other words, something like this:
<?php echo Page::urlById($article->id()); ?>
will throw an error. It is possible to set the ID number dynamically, but it requires an extra step, wrapping the variable for the ID in with the PHP intval() function, like this:
$articleId = intval($article->id()); echo Page::urlById($articleId);
With this in place, the urlById() function will work as expected.
