Dec 11
Categories and paths in ExpressionEngine
2007 at 10.53 am posted by Veerle Pieters
It’s been a while since I did some ExpressionEngine implementation work. I’ve been occupied mostly with design work only and CSS coding. Even if it’s been a while it doesn’t mean I have nothing to share on the subject. Time to refresh my memory and explain to you how paths works in EE, how you can use your own category URL titles in links, instead of C followed by a number (or category id) and how you can implement categories.
How paths work in ExpressionEngine
One of the things I found a bit confusing at first when I started using ExpressionEngine (EE) is the way the path structure work. It's actually quite straightforward and logical, but like anything new it needs some geting used to. So I thought I explain a few basics for the newbies among us.
Article page URL structure
If we look at this article page URL example:
http://veerle.duoh.com/index.php/blog/comments/apple_leopard_text_effects/
The structure of the path can be divided into:
- Weblog URL
- index.php
- Template Group name
- Template Name
- Entry title name
My Template Group name is "blog" and within this group the template "comments" is used to render the page "Apple Leopars text effects". This straightforward approach gives you flexibility on how you want your URLs and it's a pretty nice structure if you ask me.
The index.php can be removed, but how to remove the index.php is whole other story which I won't go into this time.
Note that the word seperator could be different. It depends on what you specify as Word Separator for URL Titles in the Global Weblog Preference, found under Admin > Weblog Administration > Global Weblog Preferences > Word Separator for URL Titles. I have "Underscore", but you could as well choose for "Dash".
Category page URL structure
By default the URL of a category page will have a C followed by a number, which is the category id. Like this URL for example:
http://veerle.duoh.com/index.php/blog/archive-summary/C1
However we can change that into this:
http://veerle.duoh.com/index.php/blog/archive-summary/category/Apple
As you can see, the structure of the path follows the same logical order as the article page, but then with a category indicator followed by a category name.
How to use category URL title links
Step 1: Select 'Yes' for the 'Use Category URL Titles in Links' option
This is rather simple. You simply configure this in the Weblog Preferences of EE. Go to CP Home and choose Admin > Weblog Administration > Global Weblog Preferences. Select 'Yes' for the 'Use Category URL Titles in Links' option. Once 'yes' is selected the C+number will be replaced by your category names.
Step 2: Assign a category URL indicator
Next is to assign a category URL indicator. If you have set the category URL titles to 'yes', you must choose a reserved word. I'm using the word 'category' as indicator.
Here is an example URL:
http://veerle.duoh.com/blog/archive-summary/category/Apple
Furthermore, for categories that use more then one word you can choose between 'Underscore' or 'Dash' as word separator in the Global Weblog Preferences.
Step 3: There is no step 3
That's really all there is to it. Nothing more.
Implementing categories
ExpressionEngine code
Here is an example of how you can implement an unordered list of categories using EE's Weblog Categories Tag:
{assign_variable:my_template_group="blog"}{assign_variable:my_weblog="Veerle_blog"}{exp:weblog:categories weblog="{my_weblog}"}<a href="{path={my_template_group}/archive-summary/category/{category_name}}" title="view the articles of the category {category_name}">{category_name}</a>{/exp:weblog:categories}
This is just a basic way of implementing categories. In this example EE handles the HTML output as well of the list elements (see output HTML further down in this article). As you can see I'm also using the Path Variable. The Path variable works in this basic format:
{path=template_group/template}
This:
{path=blog/archive-summary}
Will be rendered as:
http://www.example.com/index.php/blog/archive-summary/
EE will also append the category ID at the end, or if you have changed the preferences as mentioned above here, EE will add the category trigger and category URL title at the end of the URL.
There is a lot more to find out about the Path Variable on ExpressionEngine's User Guide.
Generated XHTML code
This is the generated XHTML code:
<ul id="nav_categories" class="nav_categories"><li><a href="http://veerle.duoh.com/index.php/blog/archive-summary/category/Apple" title="view the articles of the category Apple">Apple</a></li><li><a href="http://veerle.duoh.com/index.php/blog/archive-summary/category/Books" title="view the articles of the category Books">Books</a></li>...</ul>
As you can see the ul element with id="nav_categories" and class="nav_categories" is automatically generated by EE along with the li element. I haven't tried this out yet, but you can replace the id and class by your own ones, using the class="my_custom_class" and id="my_custom_id" parameters.
Furthermore, you can also choose to add style="nested" parameter for a nested category list. Or you could choose for style="linear" in case you don't want EE to output HTML code:
{assign_variable:my_template_group="blog"}{assign_variable:my_weblog="Veerle_blog"}<ul>{exp:weblog:categories weblog="{my_weblog}" style="linear"}<li><a href="{path={my_template_group}/archive-summary/category/{category_name}}" title="view the articles of the category {category_name}">{category_name}</a></li>{/exp:weblog:categories}<ul>
This way you are in control of the HTML. This is the generated XHTML code:
<ul><li><a href="http://veerle.duoh.com/index.php/blog/archive-summary/category/Apple" title="view the articles of the category Apple">Apple</a></li><li><a href="http://veerle.duoh.com/index.php/blog/archive-summary/category/Books" title="view the articles of the category Books">Books</a></li>...</ul>
That's it for now. Hope you've learned something again today.

37served
1
I’m a heavy fan of TextPattern, but I’m experiencing some limitations there… I’m thinking about picking up a good ebook around EE…
2
@Tim - The guys at Jambor-ee are doing a great project where they’re building a website in 24 days using EE.
Have a look at it here.
3
Great tutorial. I’ve used SilverStripe for a client or two but I’ve never taken a very close look at EE. You’ve inspired me to give it a spin.
4
I’ve never seen or heard of an ExpressionEngine ebook, let alone a printed book. Do any exist? If so, I’d probably buy it just to support the EE community that’s given so much to my professional life over the years.
5
Not to ruin your enthusiasm about EE, but it looks rather complicated to me. I’m using Drupal and the Pathauto module for generating Clean URLs, as Drupal calls them. The EE template engine has a drawback compared to the default Drupal templat engine: It scans the markup for specialtags like ‘{tag}’, whereas Drupal uses plain PHP code: ‘<?php echo $tag;?>’. This makes parsing the template a lot easier and faster. Next to that creating URLs for your content is easier with the Pathauto module: you can set up and edit those Clean URLs using the admin panel, rather than putting them in the template hardcoded.
Just a little tip to broaden people’s horizons ;-)
6
Bart Feenstra said:
EE doesn’t require some module to make pretty URLs, it’s built-in! hah! :)
On top of that, we can create any ‘custom’ variable, anywhere we want and have it reference, anything we want.
7
Geoff Harries said:
This is the book you’re looking for: Blog Design Solutions
It explains ExpressionEngine,Movable Type,Wordpress,Textpattern and even contains a “build it yourself” manual with PHP and MySQL
8
Great tutorial for someone who is at the beginning, when all it looks like so difficult (@Bart Feenstra). But it’s not.
I’m preparing also EE tutorial about categories, but with the support of multilanguage.
9
I’ve already tried EE and it rocks !!
Most flexible and quick to implement CMS I’ve ever tried (Used Textpattern, Drupal, Symphony)
Thnx for the tutorial Veerle ^^
10
piscator said:
- Oh, I own that one already. It has served me well. I just thought perhaps there was something else, perhaps fresher, on the market.
Bart Feenstra said:
- The unattractive user interface of Drupal’s admin was what first drove me away. Shallow, but true.
11
php is already a template language and it’s very simple to learn, why use an expression language that is more limited and complex?
12
Irene said:
Why? I’ll try to respond you, you need lots of free time to learn php for something like doing your own cms. EE is tested, supported, updated and lots of people are workin on it. People that live from that work.
I gived up of doing my own solutions after I found EE.
13
Bart Feenstra said:
Don’t get me wrong I have nothing against Drupal, it is Belgian after all and I’m sure it serves people well but just not me. The few times that I have come in contact with Drupal it seems to suffer from divitis to make things possible. EE let’s me keep my code just the way I designed it and that’s what I prefer.
Irene said:
I am a designer that has no interest in learning yet another language like PHP. Learning that from scratch to create something like my blog will take much longer than just trying to understand the EE tags system. I’m just not prepared to waste valuable time by building things from scratch when something is already tried and tested. I like to get things moving ;)
14
Veerle said:
From the brief introduction I’ve had of Drupal, I’ve not been impressed either - too many default admin-related stylesheets that you have to override with your site styles.
Having said that, a lot of the default HTML and CSS code that comes with EE isn’t all that great either. Sure you’ll be writing most of your own for most projects, but when it comes to the members and forum modules, there’s a lot of templates there so would require a fair bit of time and effort.
Geof Harries said:
In a few of the comments over at Jambor-ee people have indicated they’re waiting for EE 2.0 to come out before deciding about producing a book.
15
Veerle, very nice little tutorial on EE. I’m with you when it comes to learning EE tags system as opposed to learning a whole new markup language such as PHP. I confess that before EE I tried several others CMS’s including MT and WP with no sucess. MT is a poweful tool but I couldn’t get it to work locally, only remotely so it didnt work for me, WP is very nice but it seemed overwhelming for me. I’m building my site with EE(still in phase of experimentation) so I’ve been learning about EE tags and so forth. This is probably a stupid question but after reading one thing got me thinking… Why would you want EE to generate classes and ids? Thank you!
16
I just looked at EE the other day. I though I remembered there being a free personal version but this time around it seems you have to pay no matter what (even the trial is $10). Since I’m just looking to learn it, not implement it, it isn’t something I want to put money into.
Maybe I’ll learn a different CMS and attempt to bridge my knowledge over to EE further down the road.
17
Veerle said:
You obviously haven’t looked into Drupal enough. There isn’t a line of front-end code that you cannot adjust in Drupal. If you fail to write your own theme and instead piggy-back an existing theme, you are going to get sub-par front-end code.
That said, I don’t know why I haven’t checked out EE before. I’ve done lots of work with CodeIgnitor, so I think it’s near time I play with EE.
18
Very nice little tutorial! I’m with you when it comes to learning a new markup language for the purposes of deploying a personal weblog. I’ve been learning EE for the past week or so far I’ve been amazed on how EE has made things so much easier for designers as opposed to other CMS’s out there. I’ve tried MT and worpress and those didnt work for me. MT didn’t work due to overwhelmness of installing it locally on my imac(OS X Tiger). I jsut can’t do it! WP is pretty good but I still got stuck, easier than MT though. I’m working on my website, hoping to launch it by new years. But one thing got me thinking!(this is probably a stupid question but..) Why would you want to have EE generate classes or ids for you when you can have more control over your design when you create your own? Thanks!!
19
I must say that I love EE. I have an educational site for teaching web design. I was experiencing some limitations with Wordpress and decided to switch to EE. However, the school year was approaching and I didn’t want to redo the whole thing in a new CMS.
I decided to give it a try (with inspiration from here!) and had the whole site transferred in a day. It was really easy to learn. I was surprised.
As for the page extensions, I am not too happy with the index.php in each link. I would love to see a post going into more depth about how to remove this and how it affects urls and the site in general.
Thanks!
20
Zac said:
Have a look at this article on the EE-wiki: Remove index.php from URL’s
As for myself I can only say once you EE there’s no looking back!
21
Cavan Riley said:
What are you talking about? The core version is free and when you click download it downloads after the agreement. The $10 you are referring to is for a 30-Day hosted demo so that you don’t have to install it on your own server.
Colin Williams said:
Well for the project I did my templates were without any divitis and after being implemented by an experienced developer who only does Drupal they had, so it must be that my design the way I created it was impossible in Drupal without changing the markup of my templates. So it wasn’t piggy-backing on any existing theme at all but totally custom made. I want a system that works around my markup not the other way around by forcing me to adjust my code to fit into the CMS way of working. That’s contra productive imho.
Zac said:
The link e-man provided was already mentioned in the article. Explaining the removing of index.php can be difficult because there can be a number of things that may cause it to work or not work across servers and each situation is different. There isn’t a way that it will work guaranteed on all servers. The Wiki is the best place to start.
Juliano Moreira Dasilva said:
Well I wouldn’t. The user has the choice here to let EE deal with it yes or no. You simply leave them out if you use style=“linear”.
22
Awesome article :)
23
Jaime J Aleman said:
Drupal’s philosophy is to make a basic framework and add required by enabling modules. This is an advantage (tune your system the way you want to) but a disadvantage as well (it’s a bit hard to get for newcomers who are not used to this kind of software).
Geof Harries said:
Drupal doesn’t have a special user interface for the admin panel. It’s by default the default theme the system uses. About this matter I can also only say that you have to learn how Drupal works. It might scare newcomers, but once you get how Drupal works it’s all very logical. The whole philosophy is about not adding redundant features.
Veerle said:
I agree with both you and Colin. There’s practically no piece of markup you can’t change when using Drupal (some small markup, <b> tags for instance, contained within strings might form an exception in not very well coded 3rd party modules). On the other hand it’s quite complicated to override all the default markup. The hardest part is learning how to do that. Actually doing it is less work.
I think it’s the flexibility that Drupal provides that makes Drupal a bit harder to use than other frameworks/content management systems. For a newcomer it’s hard to customize it, but when you’re a bit more experienced you can do anything you want with Drupal.
24
I would like to point out that you should not use underscore for category and article names, instead use dashes.
Dashes vs. underscores
25
Dookie said:
Dookie, that post is almost 3 years old??
that doesn’t mean that is wrong, but some things are changed.
please check:
haacked.com, simon cox, blogoscoped.com.
26
great article, hey Veerle how you make to use that of “veerle say: etc… blackquote… ” its automatic ? how respond to a user… manual: copy paste? or what?
27
Christian said:
It isn’t automated. Next to the comment field you’ll see ‘Allowed/required’. If you click the link ‘these elements’ you’ll see what tags are allowed.
28
I know it’s not the main topic, and also, you said you don’t want to go into details with it, but removing the ‘index.php’ part from the URL can cause any problems? I read that it can mess up the 404 page not found display. I tried to type a fake url with veerle.duoh.com and it displayed your archives page. Does it actually returns the 404 error, or you set up the page to go to the archives page every time the url doesn’t exist? Thanks.
29
Peter Moricz | Liquid Media said:
I’m not Veerle, but I’ll try to respond, removing index.php is done by some little url rewriting. so, in other words, he is not deleted, he is just “passed”. so, if you enter it, in your address bar, the site will open it. I don’t know how Veerle made her 404 page, but it works normal, also on my website
Can you provide your source, where did you find that can mess up 404 page?
thank you
davor
30
Peter Moricz | Liquid Media said:
Davor is right it is done by rewriting the url using .htacess with the following:
RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
However every server config is different so I’m not sure it will work in you case as well. My 404 page looks like my archive page because I thought that was the most logical place to search for something. However it has a box with a warning as well. I guess you didn’t notice that.
31
Nice write-up. One thing I would like to know: is the name of the template always displayed in the URL? To me that seems very restrictive. I would think that the template names should be decoupled from the URls completely. URL’s should be semantic and provide rich and clear information. Like mysite.com/articles/bla-bla or mysite.com/archives/2007/10/08/, etc etc. For example, if I would look at the current URL, I would remove the section /comments/. That doesn’t at much to the URL (or maybe I’m missing something).
Not sure if you are familiar with the way wordpress handles URLs, but I find the approach taken in wordpress very good. In short, you can design your URLs anyway you want, even from within the admin section, and you can design your template system any way you want. Without those two being coupled in any strict way. Each article or post can be assigned to any pre-made template. And your URLs can be designed any way you want.
Not trying to be too critical here, just curious. Expression engine is a system on my wish list to explore, so the more I learn the better.
32
Veerle, Davor! Thanks for the reply. I saw the warning on the page. :o) I read the article from the EE website again, and it actually mentions the 404 issue:
“Important note for SEO: This method will serve all ExpressoinEngine pages with a code 200 - which means that Error Code 404 - Not Found will never be delivered, even if EE is set to use it. “.
That’s why I asked, but getting the actual 404 page (and response), or displaying a page like the Archives page with the warning doesn’t make any difference for me as far as it works fine. :o)
Thanks,
Peter
33
One more thing - and it’s totally off topic… :o) Have you actually implemented the gravatar.com gravatars? You mentioned this in an older post about the comments part of your blog. They don’t seem to show up.
Cheers,
Peter
34
Peter Moricz | Liquid Media said:
Yes I did but I switched them off because they slowed down the site too much. I’m keeping it that way until gravatar.com is always fast.
35
Veerle said:
I see the Elements, but I mean with “automatic” with comment code of EE or you add to your site?
Ill try to add but I think that dont work with quotes…
36
correction, works… in the preview I dont see the quotes… Same question:
I see the Elements, but I mean with “automatic” with comment code of EE or you add to your site?
thanks Veerle
37
After spending a lot of time learning and becoming frustrated with the limitations of the many CMS’s out there, EE was a welcome sigh of relief. I’ve ditched every other option and am strictly devoted to EE.
I have heard that Drupal has gotten better but I still think that Drupal (and most everything else other than EE) is really geared towards developers while EE is geared towards designers.
EE just works and I’ve never encountered anything with more absolute control over everything than EE has.
It just works, no modules to install (unless you want to), no trickery involved, no need to “just learn it” before you can see how great it is.
That said, I believe everybody has their own personal prefs and what works for one person might not for somebody else.
How a tutorial on using EE categories turned into a Drupal vs. EE discussion is beyond me.