General
Getting Support
Administration
Design
Wolf Reference
Plugin Development
Core Development
- Design documents
- Working guidelines
- References
Press, Graphics and Translations
Wolf CMS books section
level()
level refers to the “distance” of a page in the tree from Home Page or, more precisely, the number of elements a given page is distant from the “root” in the URI. “Home Page” (or “root” in the URI) is at zero.
You can echo the level of a page to the screen using this code:
<?php echo $this->level(); ?>
Examples
| In this URI: | this page: | is at this level: |
|---|---|---|
| http://www.wolfsite.com/ | (home page) | 0 |
| http://www.site.com/wolf/ | (home page) | 0 |
| http://www.wolfsite.com/about-us.html | about-us.html | 1 |
| http://www.wolfsite.com/about-us/contact | contact | 2 |
It is important to note that the “archive” (“blog”) type pages work this way:
| In this URI: | this page: | is at this level: |
|---|---|---|
| http://www.wolfsite.com/articles | articles | 1 |
| http://www.wolfsite.com/articles/2009/03/07/my-news | my-news | 5 |
| = http://www.wolfsite.com/articles/my-news | my-news | 5 |
In an “archive” setting, the level of my-news is always 5, even though it is the child of the articles page which is at level 1.
Usage note
level() is very useful in a test to keep things off the “Homepage” that should only appear “inside” the site:
<?php if ($this->level() != 0) : ?> ... do stuff inside the site, but not on the Homepage ... <?php endif; ?>
The if() test checks to see if the level is not '0' (= homepage), and if not, whatever appears before the endif will be run.
