April 24, 2007 ExpressionEngine and the Power of URL Segments
I had need today to serve a separated RSS feed of just my blog articles — sans links and quick-posts. At first I thought I’d simply duplicate my RSS template and call it something like rss-blog.php.
Yeah right. Not with ExpressionEngine and its support for URL segment conditionals around. Ladies and gentlemen, pay attention, because this is all it took: if segment_3 != 'blog'
Now, the when the URL is http://seansperte.com/rss/blog I can show unique content by placing it inside the if statement, like so:
- weblog="blog1{if segment_3 != 'blog'}|blog2{/if}"
See how that works? See how easy?
Okay, I should probably explain a little more.
Basically the
weblogparameter allows for multiple values (as I’ve discussed before ), but I don’t want the second value (seanasides) when the URL ends in /blog. To do this I use the “does not equal” symbol (!=) to test the URL.So, in English the statement says: if the third segment of the URL does not equal “blog”, then put
|seanasides.(And I should also note that because of this, it’s now possible to pick up a posts-only version of my RSS feed … for those that care to.)
Sean
April 24, 2007