Display Everything in next 7 days

This topic contains 2 replies, has 2 voices, and was last updated by  Stephen Harris 10 years, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #12923

    Hi,

    I’m not much of a dev.

    I want to achieve 3 Pages –

    1. Todays Events (The whole Post ) – This will be the home page
    2. Next 7 Days Events (The whole Post – including all content like archives)
    3. Maybe next 30 Days (Maybe full,maybe a list)

    If i use the shortcode-event-list I can’t work out how to add all of the content. Is this possible?

    Is there a way to show the default archives for say next 7 days? That’s pretty much what I want.

    Should I copy the archive pages as a template and change that to only show next 7 days?

    Any help appreciated.

    Chris

    chris britton
    #12930

    I’ve managed it.

    $original_query = $wp_query;
        $wp_query=null;
    
        $args = array(
        event_start_after=> 'today',
        event_start_before=>'+1 week',
        post_type=>'event',
        posts_per_page => -1
        );
        $wp_query=new WP_Query($args);
        ?>

    Attached to The Archive-event.php and saved as a template. Then saved 3 versions for 1,7 and 30. I’m sure there’s a more elegant way to do this. Especially as I’m using genesis, but i’ll work on that!

    chris britton
    #12932

    Hi Chris,

    Yup, that’s how to do it. I would use a different variable than $wp_query, and don’t forget to call wp_reset_postdata() afterwards:

    For your home page you could add the following to your home page template.

    $event_query = new WP_Query( ... )
    if( $event_query->have_posts() ){
         while( $event_query->have_posts() ):
               $event_query->the_post();
               //the_title(); the_content();// etc are all available
         endwhile;
    }
    wp_reset_postdata();

    For the two you could use the shortcode with the placeholders (see docs). Or you could create a a page template with the above code in it.

    Is there a way to show the default archives for say next 7 days? That’s pretty much what I want.

    You can add the following to your functions.php

    add_action( 'pre_get_posts', 'my_set_event_archive' );
    function my_set_event_archive( $query ){
          if( $query->is_main_query() && eventorganiser_is_event_query( $query ) ){
               if( eo_is_event_archive() && !eo_is_event_archive( 'day' ) && !eo_is_event_archive( 'month' )  && !eo_is_event_archive( 'year' ) ){
                      //Event archive, but not day/month/year archive
                      $query->set( 'event_start_after', 'now' );
                      $query->set( 'event_start_before', '+7 days' );
               }
          }
    }
    Stephen Harris
Viewing 3 posts - 1 through 3 (of 3 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.