Jb Last Segment
Get the most useful bit of your url
We all love clean urls and most of the time the most important part of the url is the last segment. For example a url of http://foo/bar/10/01/url_title has lots of data in it, but to get the actual entry url, we care most about the url_title part. It can be a pain to keep track of where in the segment_1, segment_2, segment_3.., that will be, especially if there are mulitple paths to the same resource.
Rather than tracking exactly how the url segments are built up throughout the site it would be nice to be able to consistently get the last part of the url. The last segment. And that’s exactly what this extension does. So now it doesn’t matter if the url is http://foo/bar/news/10/01/url_title or http://foo/bar/url_title – the variable * returns *url_title for all cases.
Installation
- Download and unpack JB Last Segment (also on github)
- Copy extensions/ext.jb_last_segment.php to your /system/extensions directory
- Activate the extension via System Administration > Utilities > Extensions Manager
Usage
There’s not much to do once this extension has been installed, it adds a new variable to your global variables, and you can use that variable in your templates whereever you’d like.
If previously you had :
{ exp:weblog:entries limit='1' dynamic='off' url_title='{segment_3}' }
you can now replace that with
{ exp:weblog:entries limit='1' dynamic='off' url_title='{last_segment}' }
given that the url_title is in the last segment of the url.
Support
Support and feature requests are handled via github.
