• Resolved David 279

    (@david-279)


    I am trying to create a weekly display of events unfortunately some days will have more than one event, so rather than display say 3 Mondays (or the dates thereof) I worked out that I could create a separate list view for each day – No problem but then I cot to wondering, rather than create a shortcode like this : [events_list scope=”2018-11-06″ ]<p><b> #_EVENTNAME </b> meet at <b>#_LOCATION </b> at <b>#_EVENTTIMES </b>
    <br>#_ATT{Notes}</p>
    [/events_list]

    I wondered if is possible to set a start date and then in some way do each day by setting the date as start day +1, start day +2 and so on the for each week I would only have to set one start date

    Even better if I could automate things, the Events start on a Sunday each week so ideally I’d be able to see a page with this weeks events on and a page with next weeks events on both starting on a Sunday no matter what day I looked at the page

    I’m using the example above without links as this is intended to be printed out and posted in various locations on the Saturday before the start of the week

Viewing 6 replies - 1 through 6 (of 6 total)
  • timrv

    (@tim01)

    Hello,

    If I get is correctly What you’re looking for is to display something like.

    Nov 4, 2018 (Monday)
    Some Event 1
    Some Event 2

    Nov 5, 2018 (Tuesday)
    Some Event 1
    Some Event 2
    Some Event 3

    and so one.

    You would need to do some custom coding with PHP for it.

    $now = new DateTime;
    $total_days = 7;
    $week_start = $now->modify("monday this week")->format('M d, Y'); // see ISO 8601 
    $now->modify("+1 week");
    for( $d = 1; $d <= $total_days; $d ++ ) {
     $now->modify("+1 day");
     $current_date = $now->format("Y-m-d");
     echo "<h3>" . $now->format('M d, Y') . "</h3>";
     echo do_shortcode("[events_list scope='{$current_date}' ]<p><b> #_EVENTNAME </b> meet at <b>#_LOCATION </b> at <b>#_EVENTTIMES </p>[/events_list]");
    }
    • This reply was modified 6 years ago by timrv.
    JimGasperini

    (@jimgasperini)

    This looks like it’s looking to provide something I need as well.

    When I use tested this shortcode today Nov. 9, however, the page displayed a list of events for a week beginning Oct. 31st. Why would the list start more than a week in the past?
    Thanks

    Stonehenge Creations

    (@duisterdenhaag)

    Hi Jim,

    Out of curiosity on my part, I tested Tim’s snippet for you. I made some alterations and this works on my site:
    Starting the week on Monday, November 5th.

    $now = new DateTime;
    $total_days = 7;
    $week_start = $now->modify("sunday this week")->format('M d, Y'); // see ISO 8601 
    $now->modify("-1 week");
    for( $d = 1; $d <= $total_days; $d ++ ) {
    	$now->modify("+1 day");
    	$current_date = $now->format("Y-m-d");
    	echo "<h3>" . $now->format('M d, Y') . "</h3>";
    	echo do_shortcode("[events_list scope='{$current_date}' ]<p><b> #_EVENTNAME </b> meet at <b>#_LOCATION </b> at <b>#_EVENTTIMES </b>[/events_list]");
    }
    

    It seems like $now->modify looks at the end of the day… Changing it to Sunday seems to work. Also, you want -1 week, because that means this current week (seen from the scope’s point of view)

    Thread Starter David 279

    (@david-279)

    Hi everyone

    Thanks for the replies sorry not responded before was stuck in hospital ??

    I should have mentioned I’m doing the page layout in Elementor and whilst I’m ok with css. php is not so easy for me

    I can see what is happening in theory theres a for next loop going through each day, but I’m not sure where/how I should be using the above code

    I’d really appreciate the extra help I need to get this to work

    JimGasperini

    (@jimgasperini)

    Thanks Patrick for working out this alternative. You solved this problem in another thread as well, so double thanks.

    David, you will need to add Patrick’s string of code to the functions.php file of your theme (best if it is your child theme so it doesn’t get overwritten by any updates.) Then put the shortcode (in the last line) wherever you want the list to display.

    One issue I ran into: only 10 events displayed in the list. 10 is Events Manager’s default limit of the number of events in a list, which you can change in the plugin’s settings.

    Thread Starter David 279

    (@david-279)

    Thanks for everyone who has helped me with this, possibly due to the way Elementor works I found I was getting odd results BUT by using a PHP Code Snippet to shortcode plugin it works ?? This is great I’ve made a couple of minor changes and I’m working on a couple more ideas but this is the code as of today

    <?php
    $now = new DateTime;
    $total_days = 7;
    $week_start = $now->modify("saturday this week")->format('M d, Y'); // see ISO 8601 
    $now->modify("+0 week");
    for( $d = 1; $d <= $total_days; $d ++ ) {
    	$now->modify("+1 day");
    	$current_date = $now->format("Y-m-d");
    	echo "<h3>" . $now->format('l') . "</h3>";
    	echo do_shortcode("[events_list scope='{$current_date}' ]<p>#_EVENTDATES<b> #_EVENTNAME </b> meet at <b>#_LOCATION </b> at <b>#_EVENTTIMES </b><br>#_ATT{Notes}</p>[/events_list]");
    }

    Now it could be because today is Sunday but I found in order to start on a Sunday I had to change week start to saturday, I changed the date format to day rather than the full date because the page will have the starting date at the top, temporarily whilst I’m still testing I’ve added in the event date for each event and I’ve added in an event attribute {notes} to let me add a little extra info for each event. I also set the events lost to a maximum of 21 as there will never be more than 3 club events per day later I will add a category to the shortcode to ensure only Club events are displayed on the list, note currently this is set to +0 week just because I’m testing

    • This reply was modified 6 years ago by David 279.
Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Using Scope for a custom display list’ is closed to new replies.