WordPress.org

Ready to get started?Download WordPress

Forums

Event Organiser
[resolved] yearly filter events using menu ? (9 posts)

  1. glenndm
    Member
    Posted 1 year ago #

    Hi,
    I would like to split the eventscalendar up by year using (sub)menus.
    As 2012 was the first year I used events organiser, this hasn't come up yet.

    I made a specific page template for showing the events at http://www.kartcross.be.

    Now I am trying to use submenus to the Kalender menu - using the wordpress menu system, one submenu per year.
    Only events pertaining to that year are to be shown.

    As the modification to the page template is very limited, I'd like to reuse the same template by adding the year parameter. All events carry a year category.

    <!-- Event list -->
    	<?php $events = eo_get_events(array('event-category'=>'<YEAR>' )); ?>
    	<?php if($events):

    The question: How can I pass that year parameter to the template?

    A submenu has a title attribute which could be used, but I have not yet found a way to get to it from the template

    http://wordpress.org/extend/plugins/event-organiser/

  2. Stephen Harris
    Member
    Plugin Author

    Posted 1 year ago #

    I wouldn't use categories - you can do date based queries already (to get events that start in a given year):

    $year = 2012; //Set the year - we'll discuss this in a minute
      $events = eo_get_events(array(
          'event_start_after' = > $year.'-01-01', //Events after 1st Jan of $year,
          'event_start_before' = > $year.'-12-31', //Events before 31st Dec of $year,
       ));

    Next to get the year. One way is to use a basic $_GET. The idea is that visiting

    www.example.com/events/event?event-year=2012

    Then

    $year = $_GET['event-year'];//E.g. will hold 2012

    This doesn't always work. You may find this answer on WPSE helpful about how to set up a custom query variable (in this example event-year).

    While we're at it - if this is for the main query then a much better way is:

    add_action('pre_get_posts','my_events_by_year',15);
    function my_events_by_year( $query ){
        if( $query->is_main_query() && is_post_type_archive('event') ){
             if( isset($_GET['event-year']) ){
                $year = $_GET['event-year'];
    
                //Events after 1st Jan of $year,
                $query->set('event_start_after', $year.'-01-01');
    
                //Events before 31st Dec of $year,
                $query->set('event_start_before',$year.'-12-31');
              }
        }
    }

    Of course the above can be improved by registering the query variable and using get_query_var() to retrieve the value (the year).

    Code not tested, but should work in principle.

  3. glenndm
    Member
    Posted 1 year ago #

    Hello Stephen
    My thanks for your extensive reply
    I'll try it asap

    glenn

  4. glenndm
    Member
    Posted 1 year ago #

    Hi Stephen,
    Just an update: I finally got the split events working.

    I struggled with the custom parameter; representing less than 10 lines of code and abundantly documented on the web.
    I couldn't get it to work.
    Finally I tried with a blank WP site; it worked immediately ?!

    Back to the main site, copying the relevant code verbatim - it fails!

    At the very last, I discovered the problem:
    The events page was set as the static front page of the wp-site.

    Internally this shortens the url of the events page to http://www.example.com instead of http://www.example.com/events
    Also this resulted in the default post template being shown instead of the events template.
    I tried every rewrite rule I could think of, without success.

    Too much of a (tired) WP newbie, I gave in (for now), setting "Front page Displays = your latest posts"

    The test site works as intended (but for showing the events as start page).
    I now only have to modify the live site accordingly (hopefully).

    Thanks for your help
    glenn

  5. nisamp17
    Member
    Posted 1 year ago #

    hi glenndm

    can u pls mail me the entire code for me if you solved the problem.. am also facing the same problem.. send me to this id pls.. nisamp17@gmail.com

    hopefully
    Nisam

  6. Stephen Harris
    Member
    Plugin Author

    Posted 1 year ago #

    Actually year, month and day archives will be available in 1.7 (see this post http://wp-event-organiser.com/blog/1-7-ready-for-beta-testers-translators/).

    Currently its in beta - but should be out sometime this week.

  7. glenndm
    Member
    Posted 1 year ago #

    @nisamp17: please read the above posts too.

    relevant code excerpt:

    if( isset( $wp->query_vars['Season'] )) {
    		$events = eo_get_events(array('event-category'=>  $wp->query_vars['Season'] ));
    		print '<div id="title_important" ><b>Kampioenschap - Championnat '. $wp->query_vars['Season'].'</b></div>';
    
    	} else {
    		$events = eo_get_events(array('numberposts'-1));
    	}

    I filter on category Season (=year), because it suited my purpose better.
    The result: http://www.kartcross.be
    (Menus are a bit wonky)
    The update Stephen (Hi!) is working on will filter on the post dates.

  8. nisamp17
    Member
    Posted 1 year ago #

    hi glenndm

    Actually i want to list the new added events on my header menu as you done in previous post.. With that in each of my event page i have to add dynamic sidebar containing Organizing Commitee, Registration, Venue details, etc.. when a next event adding the sidebar menus may be differ..can you pls help me..?

    Hopefully
    Nisam

  9. nisamp17
    Member
    Posted 1 year ago #

    hi...

    I want to list the new added events on my header menu.. With that in each of my event page i have to add dynamic sidebar containing Organizing Commitee, Registration, Venue details, etc.. when a next event adding the sidebar menus may be differ..anyone can you pls help me..?

    see the example site..
    http://www.hacu.net/hacu/HACU_101.asp

    here in conference menu they annually adds the conferences..then each conference page contains different sidebars.. can you pls help me to do the similar..

    Hopefully
    Nisam

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.