Documentation

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

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:

  1. for URL: http://www.wolfsite.com/
    • getUri() = [nothing]
  2. for URL: http://www.mysite.com/wolf/ (when installing Wolf CMS in a subdirectory 'wolf')
    • getUri() = [nothing]
  3. for URL: http://www.wolfsite.com/about_us
    • getUri() = about_us
  4. for URL: http://www.wolfsite.com/about_us.html
    • getUri() = about_us
  5. 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).

 
functions/geturi.txt · Last modified: 2011-09-12 00:46 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Copyright 2010 wolfcms.org / design by yello studio / Wolf CMS Inside