Light-weight, fast, simple and powerful!
Translations of this page?:


This function1) makes it possible to create a “persistent link” to a page, so that the link will not break even if the page is moved to a different location in the page hierarchy. It has the same options as the link function (see that page for explanations and examples). The page ID is used as the basis for the link, rather than the page's “slug”.2)

See also: findById(), urlById().


<?php echo Page::linkById(3); ?>


<?php echo $this->linkById(3); ?>

where “3” in the example above is the “id” of the targetted page.

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 may not pass the filter test set by the linkById() function, since the variable might be a “string” rather than an “integer”, which is what this function requires. In other words, something like this:

<?php echo Page::linkById($article->id()); ?>

might throw an error. It is possible to set the ID number dynamically, but it might require an extra step, wrapping the variable for the ID in with the PHP intval() function, like this:

$articleId = intval($article->id());
echo Page::linkById($articleId);

Another more compact solution uses PHP (int) to cast the value as an integer:

echo Page::linkById((int)$article->id());

With either of these solutions in place, the linkById() function will work as expected.

1) Added in Wolf 0.6.0.
2) See the "id" documentation on how to find the ID of any given page.
functions/linkbyid.txt · Last modified: 2012-06-04 16:14 by David
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Copyright 2010 / design by yello studio / Wolf CMS Inside