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.

How to create a list of people who's birthday fall on the month we're in - Channel Entries not Members

October 23, 2013 5:44am

Subscribe [2]
  • #1 / Oct 23, 2013 5:44am

    Kubik101

    155 posts

    I am creating a sponsorship site which will list children you can sponsor.

    There will be 300 children in the database all channel entries.

    When a user looks at the donate page I would like to only show the children who’s birthday falls in the month we are in, and limit it to 20.

    So in this case if we looked now, it would show all children born in October.

    I am looking for any way this can be done.
    Not fussed with what data needs to be entered to do this, additional fields etc or even categories as months.
    I would ideally like it all to be done by a date field.

    To clarify:
    - Limit results to 20
    - Only show children who’s birthday is in the month we are in

    Any help will be appreciated.

    Thanks.

  • #2 / Oct 23, 2013 2:58pm

    Rob Allen

    3114 posts

    I’d approach it like this….

    Create three custom fields for day, month and year:

    Day
    Field name birth_day
    Select field manually populate
    Values 1-31

    Month
    Field name birth_month
    Select field manually populate
    Values 1-14

    Year
    Field name birth_year
    Text input limit to 4 characters

    Create a template to show the results, eg birthdays/index:

    {exp:channel:entries channel="your_channel" search:birth_year="{segment_2}" 
    search:birth_month="{segment_3}" search:birth_day="{segment_4}"}
    Name: {title}
    {/exp:channel:entries}

    ... you may need dynamic=“no” as a parameter as well so test it 😊

    To link to a birthdays page for any day link to:

    site.com/birthdays/[year]/[month]/[day] so something like site.com/birthdays/2013/10/23 would bring back birthdays happening today (when I’m posting this…lol)

    Now, for just listing the current month, change the entries tag to:

    {exp:channel:entries channel="your_channel" search:birth_year="{segment_2}" 
    search:birth_month="{segment_3}"}
    Name: {title}
    {/exp:channel:entries}

    Then for the link use

    site.com/birthdays/{current_time format=" %Y/%n"}

    .which outputs site.com/birthdays/[year]/[month]

    Using current_time will always output the current year and month values.

  • #3 / Oct 23, 2013 9:18pm

    Kubik101

    155 posts

    Thank you so much Rob.
    I never knew about search:channel_field=”” on channel entries.
    Awesome to now know.

    I took your idea and extended it so I can have a fixed url.

    I created a snippet “current_month”:

    {current_time format='%m'}

    Then used the following channel entries tag:

    {exp:channel:entries channel="my_channel" search:birth_month="{current_month}"}
    {title}
    {/exp:channel:entries}

    As you suggested this only meant creating one additional field for month.
    So all in all a great solution, thanks for your help.

    Cheers.
    =)

  • #4 / Oct 24, 2013 7:33am

    Rob Allen

    3114 posts

    Excellent, glad I was able to point you in the right direction.

    Yes the search: parameter is a good one to know, you can now maybe see lots more possiblities for manipulating channel entries!

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

ExpressionEngine News!

#eecms, #events, #releases