The Importance of Semantics: Dates
So, as it goes, with my move to Oregon I became geographically closer to several other EllisLab folks; and this became highly advantageous when Rick adventured into Portland and he, Paul, and myself went out to dinner. This was an important occasion, because previously I had lived in the NorthEast, and had not been able to make it to SXSW, I had not yet met any of my wonderful EllisLab family! Neither had I yet ventured into Portland, so I had a very exciting evening.
Now, this is a big step and so, of course, I wished to write about it. Last week we established a “Work” category and how to access all articles in that Work category. But this time, not only is my post about work, it is also about a specific, highly memorable day; and I, being the overly eager writer that I am, just had to post about it the very moment I got home.
Now, we know that we can view by category, as posted in last week’s article. But, can we view by date? Let’s find out!
Now, remember, this began as an adventure in exercising the weblog entries tag. So, we have a single, plain template with just this code:
{exp:weblog:entries weblog="default_site" limit="10" disable="trackbacks"}
<h2>{title}</h2>
{body}
{/exp:weblog:entries}
We’ve now viewed this template as a single and multi entry page and as a category page. How about a date-based archive?
We can view date-based archives in two ways by default in ExpressionEngine - and a whole lot of other ways, which we’ll touch on in another article (hint: stay tuned!). The two default ways are by month, and by day.
Shall we begin by month, then drill-down to day? As clarification, this all refers to the Entry Date for each article.
Consider this URL:
http://example.com/index.php/site/index/2007/08/
We learned previously that in the third segment, a plain number will be treated as an Entry ID. In this example, without the /08/ - 2007 would be considered an Entry ID. However, EE is far too smart, really. By appending a fourth segment with a month, EE knows that we are now looking for a particular date, and not an entry ID. In this case, we’re looking for August (08) of 2007. Visit the template above, make sure you have some entries in August, and voil√†! Only the entries from August of 2007 are displayed.
But, we want to drill down to a particular date and read about all that happened on 21 August, 2007 - the day of my aforementioned adventure. It’s easy, simply append the day of the month at the end of the previous URL:
http://example.com/index.php/site/index/2007/08/21/
So in our earlier link we saw that, simply from the URL, EE knew that we wanted to view posts from August 2007. Now EE knows that we want to see all posts from the 21st of August, 2007, and all it took was adding the day to the end of the URL!
Pretty neat, eh?
That concludes the default URL handling for EE, and now I must think up more articles to write to help everyone more easily achieve that wonderful “aha!” moment.


