Client Login

Cameron Senior - P.O Box 653, Crows Nest, NSW, 1585, Australia  –  Phone. +61 414 355 498

Category ID from URL in ExpressionEngine

 

Put 10 economists in a room and ask them the same question - chances are you will likely get 11 different answers! Well It's the same for ExpressionEngine; there are many different approaches to achieve the same goal. The Low Seg2Cat extension let me do just that today, when I wanted a quick and efficient means of grabbing the Category ID from a URL.

I was building a simple product catalogue today and this relied heavily on the use of nested categories. I needed a way to get the Category ID from the URL to work with the Child Categories plugin to dynamically fetch the relevant product set from it's category. With the Low Seg2Cat extension, I didn't have to bother with custom PHP to get the Category ID from the specific URI segment.

So what does the Extension do?

The Seg2Cat extension allows you to grab both the Category Name and Category ID from the URL by specifying the appropriate Segment in a function call. This came in handy for me as I was building a product catalogue and wanted to stay away from having a dirty big "Category" ruining my beautiful semantic URL!

Low Seg2Cat loops through the segments of the current URI, matches them against existing categories, and registers the matching categories as global variables, which you can use in your templates.

Low Seg2Cat gives you easy access to category ids so you can use url_titles in your URIs without the use of the Category URL Indicator or custom PHP.

Final thoughts

Installation was a snap – as most ExpressionEngine extensions are, and I was up and running in no time. I'll be using this extension again!

Download it from here: Low Seg2Cat extension

 

Do the Social thing...

Delicious 48 Sumbleupon 48 Twitter Boxed 48