General
Getting Support
Administration
Design
Wolf Reference
Plugin Development
Core Development
- Design documents
- Working guidelines
- References
Press, Graphics and Translations
Wolf CMS books section
getUri()
This function will return the "slug" values which point to a given page.
Notes
For this code: <?php echo $this->getUri(); ?>, note the different results:
- for URL: http://www.wolfsite.com/
- getUri() = [nothing]
- for URL: http://www.mysite.com/wolf/ (when installing Wolf CMS in a subdirectory 'wolf')
- getUri() = [nothing]
- for URL: http://www.wolfsite.com/about_us
- getUri() = about_us
- for URL: http://www.wolfsite.com/about_us.html
- getUri() = about_us
- for URL: http://www.wolfsite.com/articles/2009/11/10/my_first_article
- getUri() = articles/my_first_article
Note in the last example that only the “slug” values are given, not the “yyyy/mm/dd” values generated by the Archive plugin. For this page behaviour, compare the related “constant”, CURRENT_URI.
Examples
Finding "top slug" for page tree
It is often useful to find the slug of the top (level 1) page in a tree. This can be using for conditional navigation, or setting a unique background or banner for that area of the site, etc. The most simple code for this can use the getUri() function:
// Returns the top parent slug: $topParent = reset(explode('/', $this->getUri()));
For the URI of fruit/apples/granny-smith with the code above, then echo $topParent; would return fruit.
Get list of "sibling" pages
If one wanted a list of “sibling” pages (at same level, with same parent), you wouldn't know in advance how many slugs were needed in the find-> statement, so here again getUri() should be used. The following code (to be used in a Layout) produces a simple sibling list of this kind:
- Sibling1
- Sibling2
- Sibling3
<?php if ($this->level() > 0) : ?> <ul> <?php foreach ($this->find($this->parent->getUri())->children() as $sibling) : ?> <?php if ($this->slug() != $sibling->slug()) : ?> <li><?php echo $sibling->link(); ?></li> <?php endif; ?> <?php endforeach; ?> </ul> <?php endif; ?>
Note that the code as given omits the current page. To include all sibling pages, including the current page, remove the “inner” if/endif statements (lines 4 and 6).
