Steven Kovar - Interactive Designer

Tech Journal

Latest Entries

Tech and Design

iPhone

Web

Motion

Mining date-based ExpressionEngine URLs

August 12, 2011

For a calendar project I’m working on, I ran into the need to create an ExpressionEngine readable date from URL segments.

My segments are set up as follows:

www.mysite.com/templateName/cateogory/YYYY/MM/DD 

In order to format the URL into a date ExpressionEngine understands, I set PHP to “output” and created a PHP variable using the segment variable feature of EE to reformat:

<?php 
$mydatebegins 
"{segment_4}-{segment_5}-{segment_6} 00:00"
?> 

We can stop there, and we have a date you can use in the Channel Module to filter entries. What I needed, however, was a string to use in the Query Module to query the database and find entries based on the date in the URL.

I then echo this as a string using PHP strtotime, as follows, as an embedded template variable:

{embed="myembeds/myTemplate" startDate="<?php echo date( strtotime($mydatebegins));?>"

So, this little technique didn’t take long, and sent me on my way to creating my own calendar with a little more flexibility than what the default ExpressionEngine dynamic url behaviors provide.


Reader Comments


There are no comments yet.

Leave a Comment

Commenting is not available in this channel entry.