Changing number of events shown based on the view selected

Home Forums Calendar Products Events Calendar PRO Changing number of events shown based on the view selected

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #961264
    Eric
    Participant

    Hello, I’m wondering if there is a way to change the number of events shown based on which view is being used. I have mine set to show 10 events in the list view currently.

    However, when switching to map, it also only shows 10 events at a time. I would like the map view to show all the events at once. Is this possible? Could you at least point me in the right direction of what I would need to modify to make something like this work? I feel the map view is very misleading to users if it is only showing a small amount of events at once. Thanks.

    #961388
    Barry
    Member

    Hi Eric,

    You could add some code like this to an appropriate location (including your theme’s functions.php file):

    https://gist.github.com/barryhughes/5125014d9c27bc0da7b2

    Note that this sets the number of events to show per page in map view to 100, but as indicated in the comments you can change this to -1 if you truly want there to be no limit whatsoever (but doing so may pose a performance risk, depending on how many events you are fielding!).

    I hope that helps 🙂

    #961598
    Eric
    Participant

    Hey Barry,

    Thanks,that code is awesome! I figured it would be something very similar but just couldn’t wrap my head around what function to start with. I’ll have to get with my client and figure out an appropriate # of events to show at once, and maybe add a more clear message staing the map is only retuning a partial list.

    Are there any other functions built in that would query the amount of results displayed out of the total amount?

    #961768
    Barry
    Member

    Hi Eric,

    I’m not 100% sure if this is what you are asking but in the context of a WP_Query object:

    • found_posts tells you the total number of posts that would be returned by the query if there was no pagination
    • post_count is the number that have actually been returned (typically this is equal to or less than whatever you set posts_per_page to)

    In straightforward cases, such as list-like views (including map view) you can grab this directly from the $wp_query global:

    $total = absint( $GLOBALS['wp_query']->found_posts );

    I hope that helps!

    #961853
    Eric
    Participant

    Thanks Barry, that is very close to what I’m setting out to do! I have been able to successfully display the # of posts shown out of the total #, using the following code:

    $displayed = absint( $GLOBALS['wp_query']->post_count );
    $total = absint( $GLOBALS['wp_query']->found_posts );

    And then this to display it in:
    <h4>Showing <?=$displayed?> out of <?=$total?> events.</h4>

    Which would return “Showing 20 out of 65 events”.
    What I have not figured out yet, is how to make it count, so that it would be “Showing 1 – 20 out of 65 events”, or “21 – 40 out of 65 events” when the next page of results is selected.

    #961899
    Barry
    Member

    Hi Eric,

    If the user has advanced beyond the first page then the query vars should include whatever number has been “paged”, so you can pull this in and do the necessary calculations from there 🙂

    codex.wordpress.org/Class_Reference/WP_Query

    This is really custom development territory though so I’m afraid we aren’t going to be able to help further (and I’ll close this topic accordingly) but hopefully that gives you what you need to move toward a complete solution.

    Thanks again!

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Changing number of events shown based on the view selected’ is closed to new replies.