ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

List 2 month header and events below.

April 17, 2012 7:33am

Subscribe [3]
  • #1 / Apr 17, 2012 7:33am

    ZEDG

    32 posts

    Could someone please help expalin how to do this, or point me in the right direction.

    I have a channel named Event Calendar, that consists of only 1 field - being ‘date’.
    So the user creates a new entry, gives it a title (event), and selects the date.

    Now on the page I want only the current and follwing month to appear. The month would be the header, and each event entry that occurs within that month to appear below it:


    April 2012     May 2012
    -event 1         -event 4
    -event 2         -event 5
    -event 3


    Is this possible? Any help is appreciated.


    I already have the code below within my channel:entries tag, but once again not sure how to specify to show the events for that month only.. plus output the same code but for the following month (and its events).

    {date_heading}{eventdate format="%F"}{/date_heading}
    <h2>{eventdate format="%j%S"}</h2>
    <h3>{title}</h3>
  • #2 / Apr 25, 2012 7:55pm

    e-man

    1816 posts

    You’re on the right track have a look at the “start_on”
    http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#start-day
    and “stop_before” parameters:
    http://ellislab.com/expressionengine/user-guide/modules/channel/channel_entries.html#stop-before

    both can be set dynamically using a little php, it’s all in the docs.

    Also check archive month:
    http://ellislab.com/expressionengine/user-guide/modules/channel/archive_month_links.html
    Hope this helps!

  • #3 / Apr 26, 2012 1:04am

    ZEDG

    32 posts

    Thanks for your help..
    I have tried a few things but have no idea how to code php(!?) Plus the link you provided shows how to set the date range to display by seconds? How would i specify first day of the month - last day of the month?

    <?php
            $start_time = $this->EE->localize->decode_date('%Y-%m-%d %H:%i', $this->EE->localize->now - ?????);
            $current_time = $this->EE->localize->decode_date('%Y-%m-%d %H:%i', $this->EE->localize->now - ?????);
    ?>
    
    {exp:channel:entries channel="event_calendar" sort="asc" start_on="<?php echo $start_time; ?>" stop_before="<?php echo $current_time; ?>" }
    {date_heading display="monthly"}{eventdate format="%F"}{/date_heading}
    <h2>{eventdate format="%j%S"}</h2>
    <h3>{title}</h3>
    <p>{/exp:channel:entries}

    ANY help is appreciated.!?

    As a rough test (without using php) i tied using the line below, just to see if the events from that date range in the system showed, however all events in the system were showing. What am i missing?

    {exp:channel:entries channel="event_calendar" sort="asc" start_on="2012-04-01 00:00" stop_before="2012-04-30 00:00"}
  • #4 / May 02, 2012 12:24pm

    e-man

    1816 posts

    Sorry for the late reply, things have been hectic.
    This should work, be sure to set php to input on your template since the php is used as parameter for your entries loop. This outputs a definition list but it can be adjusted to whatever markup you need.

    <?php
    $current_month = date('Y-m-01');//1st day of current month
    $next_month = date('Y-m-d',strtotime("$current_month + 2 months - 1 day")); //last day of next month  
    ?>
    <dl>
    {exp:channel:entries channel="yourchannelnamehere" orderby="date" sort="asc" start_on="<?php echo $current_month ?> 00:00" stop_before="<?php echo $next_month ?> 00:00" disable="categories|member_data|pagination" show_future_entries="yes"}
    <dt>{date_heading display="monthly"}Events in {entry_date format="%M"}{/date_heading}</dt>
    <dd>{entry_date format="%m, %Y"} - {title}</dd>
    {/exp:channel:entries}
    </dl>

     

  • #5 / May 06, 2012 1:04pm

    ZEDG

    32 posts

    Thanks very much for your help and reply.
    It is very much appreciated.

    OK, now i understand. It is using the ‘Entry Date’ field that appears under the ‘Date’ tab.

    For my channel, i have a separate date field (eventdate1) that the user selects the event date from. Is it not possible for the system to work out the event (start & stop) date based on what is selected in my own custom date field?

    (I understand that i need to add a custom query.)

    + also, i actaully have two date fields (eventdate1) (eventdate2). This is since some events go over a few days - so that if the user selects a date from the second field, then both dates show with a dash:

    {eventdate1 format="%F %j%S"}{if eventdate2} - {eventdate2 format="%j%S"}{/if}

     

  • #6 / May 07, 2012 4:08am

    e-man

    1816 posts

    Thanks very much for your help and reply.
    It is very much appreciated.

    OK, now i understand. It is using the ‘Entry Date’ field that appears under the ‘Date’ tab.

    For my channel, i have a separate date field (eventdate1) that the user selects the event date from. Is it not possible for the system to work out the event (start & stop) date based on what is selected in my own custom date field?

    Not quite sure what you mean, but in the above code you can swap out entry_date by your own date field and it will still work.

  • #7 / May 07, 2012 11:46am

    ZEDG

    32 posts

    I have noticed that when the actual ‘entry date’ MONTH is different between entries, it displays the entries with their own month header:

    Events in May, 2012
    10th - Event one (entry date is in may)
    18th - Event Two   (entry date is in may)

    Events in May, 2012
    22nd - Event Three (entry date is in april)

    Events in June, 2012
    10th - Event Four (entry date is in june)

    Events in June, 2012
    29th - Event Five (entry date is in may)


    Is there a way to prevent this?


    ps: I purchased the ‘Date Field Filter’ add-on so it would display entries based on my custom date field.

  • #8 / May 07, 2012 11:55am

    e-man

    1816 posts

    Not sure how much further I can help - my code snippet above will use the entry_date to order the entries - I tested it on my own site, worked fine there.
    Maybe you need to start looking into something like Solspace Calendar http://www.solspace.com/docs/addon/c/Calendar/ if you need more calendar like functionality.

  • #9 / May 07, 2012 12:22pm

    ZEDG

    32 posts

    The problem is due to the tag {date_heading} is basing itself off entry_date and not my custom date field - that is why event entries created on different months appear under separate headings.

    If the Calendar add-on is the only way around this, and will make events appear exactly as i need then i guess that is the solution. (It is quite an expensive add-on for the basic 2-month events display required for my clients intranet.)

    ..but now just seeing that ‘Calendar’ only works for the primary site when using MSM, means the add-on is a no go (since the intranet is the secondary site).

    !

    Plus, if i get my client to simply use the ‘Entry_Date’ field to set the event date, instead of the custom date field, is there any way to allow a ‘second’ date in case the event runs over multiple days?

    Or would the only solution be to set the ‘first’ date via the entry_date field, then have a second custom ‘to’ date field under the Publish tab?

  • #10 / May 07, 2012 12:50pm

    e-man

    1816 posts

    Or would the only solution be to set the ‘first’ date via the entry_date field, then have a second custom ‘to’ date field under the Publish tab?

    I’d go that route. You can use publish layouts to make the standard entry date and your custom 2nd date hard to miss on the entry form. http://ellislab.com/expressionengine/user-guide/cp/content/publish.html
    E.g. I often pull categories away from their tab and inside the entry form, impossible to miss for clients that way, if it’s under a tab it tends to be forgotten 😊

  • #11 / May 16, 2012 2:59am

    ZEDG

    32 posts

    I finally got around to completing this.
    Thanks very much for your help.

    I didn’t realise you could move fields around from other tabs (or customise what tabs appear, etc). Spent too much time trying to get it all to work using a custom date field.

    Cheers.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases