Part of the EllisLab Network

Blog & News

Lisa Wess
Director of Community Services

The Importance of Semantics: Displaying Categories

As some of you know, I recently (as in two weeks ago) moved from Massachusetts to Oregon.  Yesterday my “stuff” arrived, as I so gleefully bragged on Twitter.  Why, you might ask, am I sharing this with all of you?  Well, this article marks my first work-day in an “office”!  Most of you probably don’t know that all those years of answering technical support questions occurred on a couch with a laptop on my lap (ironic, eh?), and so I am especially proud today to be sitting at a desk, in a computer chair, looking out a window and sharing insights with you all.

A desk with a chair.  It’s a really novel luxury that too many people take for granted.  Learn to love your desk, it’s a much nicer work environment, really! =)

As a working basis for this article, shall we say that I wanted to write on my site all about my work environment, thus giving me a place to brag about my new office.  I could use the category “Work”, and by using categories, allow my audience to view all of the entries where I discussed work.

So, with that as our premise, shall we discuss categories and EE?

Last week’s article discussed the difference between single-entry and multi-entry pages.  A category page is a multi-entry page, so let us begin there, in category-land, and discuss how the URL works with multi-entry pages in regards to categories.

For the purposes of this article we are working with one category:

Category Name: Work
Category ID: 3
Category URL title: work

Also, remember, we’re still using the exact same tag from last week’s article:

{exp:weblog:entries weblog="default_site" limit="10" disable="trackbacks"}
<h2>{title}</h2>
{body}
{
/exp:weblog:entries}


Now, say that you wish to view all of the entries in the ;Work” category.  By default, ExpressionEngine uses category IDs, so you would visit your template like so:

http://example.com/index.php/site/index/C3/

Here we can see that segment_3 contains a number preceded by a capital C; this tells ExpressionEngine that you are viewing a Category Page with the Category ID of 3.  The “C” is important because without it - with just a number - EE would think you are using an entry ID instead of a category ID.  The “C” says to EE, “Hey, you - this is a category!” - and so it will display the last 10 entries in the Work category.

It is very popular to, instead, use the category name instead of ID.  So if you have that option chosen, then you would visit your Category Page at this URL:

http://example.com/index.php/site/index/category/work/

Here things are a little different.  Segment 3 contains the category trigger word (default of “category”) and so ExpressionEngine knows that Segment 4 is going to contain the Category URL Title, and thusly displays the last 10 entries in the category of Work.

The category trigger word here is important because without it, EE will think that “work” is a URL title, and we don’t want that, we want to show all entries in the Work category, so we need the trigger to differentiate between a category page and a single-entry page.

This is a multi-entry page. Why? Because it isn’t displaying a single-entry, instead it displays the last 10 entries, limited by the category indicated in the URL.  It is important to note that even if you limit it to 1, it is still a “multi-entry page” as far as EE is concerned.

Fantastic!  Now we’ve done categories and single-entry pages or permalinks.  There’s even more you can do with just the “out of the box” functionality combining the weblog entries tag with the URL, and I’ll write more on that later.  Stay tuned, eh?