EllisLab text mark
Advanced Search
     
Using dates dynamically in URL
Posted: 29 February 2012 01:22 PM   [ Ignore ]
Avatar
Joined: 2005-07-23
124 posts

I have two related questions.

1. - ExpressionEngine allows you to dynamically filter entries by a date passed in the URL like:

Dayhttp://www.mysite.com/group/template/2012/02/29

Monthhttp://www.mysite.com/group/template/2012/02 

However, I cannot find this documented in the EE User Guide. If it is documented in the EE User Guide, could someone please give me a link to the doc page? If not, can this be added to the docs?


2. - Can URL date filtering be used to show entries in a specified date RANGE? If so, how?

Thank you,
PJ

 Signature 
 
Posted: 01 March 2012 02:27 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-18
7340 posts

Hi Visiluna,

You can certainly pass that info to the channel entries tag, and the parameters are documented in the User Guide.

What is missing, however, is a solid example:

exp:channel:entries channel="news" limit="10" year="{segment_3}" month="{segment_4}" day="{segment_5}"}
    
<h2>{title}</h2>
    
{body}
{
/exp:channel:entries}
---
exp:channel:entries channel="news" limit="10" year="{segment_3}" month="{segment_4}"}
    
<h2>{title}</h2>
    
{body}
{
/exp:channel:entries} 

2. - Can URL date filtering be used to show entries in a specified date RANGE? If so, how?

You would need to work with your segment variables and the start_on= and stop_before= parameters, but you can use those to get a date range of entries.

Note that those parameters expect a specific format in order to work.

Cheers!

 Signature 

How may I help you?

 
Posted: 01 March 2012 04:01 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2005-07-23
124 posts

I’m not sure I was clear in what I was asking. I’m not referring to using {segment_x} variables to populate parameters.

Let me clariy.

Create a template with the following code:

{exp:channel:entries channel="my_stuff"}
   
<p>{title}</p>
{/exp:channel:entries} 

Load that template by going to the URL: http://www.mysite.com/group/template/
(Please note that I have removed “index.php” for these examples because I do that on every site.)

This template with this URL produces a list of titles of all entries in the “my_stuff” channel.

Now load the same template again, but with the following URL: http://www.mysite.com/group/template/2011/12/23

This will produce a list of titles from the “my_stuff” channel, but only entries with an entry_date of 12/23/2011.

No parameters needed. This is an automatic behavior of ExpressionEngine. A behavior for which I can find no current documentation. (See question #1 in my original post.)

It is this behavior I was hoping could be used to limit display to entries within a specified date range. (Original question #2)

How might you use {segment_x} variables with the ‘start_on’ and ‘stop_before’ parameters?

I tried this:

{exp:channel:entries 
   channel
="my_stuff" 
   
start_on="{segment_3}-{segment_4}-{segment_5} 00:00" 
   
stop_before="{segment_6}-{segment_7}-{segment_8} 23:59"}
   
<p>{title}</p>
{/exp:channel:entries} 

With this URL: http://www.mysite.com/group/template/2011/12/23/2012/01/31

But it didn’t work.

 Signature 
 
Posted: 02 March 2012 04:09 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2005-10-18
7340 posts

No parameters needed. This is an automatic behavior of ExpressionEngine. A behavior for which I can find no current documentation. (See question #1 in my original post.)

You are correct, it is not in the User Guide.

In order for this to work, tell channel entries to ignore the URL using dynamic=“no”

{exp:channel:entries 
   channel
="my_stuff" 
   
start_on="{segment_3}-{segment_4}-{segment_5} 00:00" 
   
stop_before="{segment_6}-{segment_7}-{segment_8} 23:59"
   
dynamic="no"
}
   
<p>{title}</p>
{/exp:channel:entries} 

That way EE won’t try to perform it’s magic automatically.

Cheers,

 Signature 

How may I help you?

 
Posted: 02 March 2012 04:32 PM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2005-07-23
124 posts

Hey, whaddya know. That does work!

Thanks! Just saved me a bunch of custom SQL.

PJ

 Signature 
 
Posted: 02 March 2012 08:53 PM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2004-05-13
3806 posts

Hi Visiluna,

REally glad to see that Dan was able to get you all sorted out. I’m going to close out this thread, but feel free to post again when you have more questions.

Sean

 Signature 

web: Caffeine Creations twitter @CS_sean