Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Hello again forum and KK!

I have a question about kind of "calendar" that I need..

there is a template where pages are generated, each page is an event with a specific date, sometimes dates are for months in advance…

There should be a page that fetches the events taking place in the current month and display them…It should be therefore possible that the client can enter dates herself...

My question is:

I use editable region   type='datetime'? How could I fetch then only the events (pages) from the current month? I think of fetching them in the list view (cause folder view is for submenus)

Thanks in advance

Tanja
Hi Tanja,

Are you using the type='datetime' you mentioned for storing the event date instead of the recommended 'publish date' system field?

Please let me know. Thanks.
HI KK!

Yes, I use
Code: Select all
 <cms:editable 
            name='event_date'
            label='Date'
            desc='Enter date of the course, workshop, concert, lecture etc.'
                             type='datetime' />

And then I fetch pages in the folder view with:
Code: Select all
<cms:pages folder=k_folder_name orderby='event_date'  order='asc'>
  </cms:pages>


And for the list-view, in the moment I can fetch just all ever added pages with:
Code: Select all
<cms:pages orderby='event_date'  order='asc'> </cms:pages>

But I would need the current month only
or is there a better way to do this?

Thanks

Tanja
OK, the process is more or less what we used in the following similar thread -
viewtopic.php?f=2&t=8194

In the code below, we use PHP to calculate the first date of the current month and of the next month. These are set as Couch variables named 'my_start_on' and 'my_stop_before'.
Code: Select all
<cms:php>
    global $CTX;
   
    // First day of the current month
    $CTX->set( 'my_start_on', @date( 'Y-m-01', @strtotime("now") ), 'global' );
   
    // First day of next month
    $CTX->set( 'my_stop_before', @date( 'Y-m-01', @strtotime("next month") ), 'global' );
</cms:php>

Now we can use the variables calculated above in our cms:pages loop to fetch pages that have an event_date greater or equal to the start date and smaller than the end date (effectively selecting only the current month)-
Code: Select all
<cms:pages show_future_entries='1' custom_field="event_date >= <cms:show my_start_on /> | event_date < <cms:show my_stop_before />">
   ...
</cms:pages>

Hope this helps.
Thanks a lot !!!!!!!!!!!!!

:) Works perfectly!!!!!!!!!


best regards

Tanja
moved
6 posts Page 1 of 1
cron