Non-AJAX navigation for List view

Home Forums Calendar Products Events Calendar PRO Non-AJAX navigation for List view

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #951300
    Marty
    Participant

    Hi there,

    Out-of-the-box, ECP uses JavaScript to power the Previous Events / Next Events links at the base of List view. For various reasons, the site I’m working on needs those to be regular, non-JS links.

    Last time I tackled this was circa ECP 3.7, and I used tribe_get_past_link() and tribe_get_upcoming_link() as a base, appending “paged” variable and such to get the desired links. Like so:

    https://gist.github.com/halfempty/a99abf2c883d88333380

    Now I’m updating to 3.9.1 and the behavior of those two functions has changed. Before I go down the rabbit hole of rewriting my functions, are there any functions already in core that will do this job?

    Thanks!

    #951323
    Matthew
    Member

    Howdy Marty – that’s a solid question!

    Disabling Ajax-driven paging on the month and the day view works swimmingly with this tip. But, as you’re experience has shown you, non-Ajax pagination on the list view doesn’t work so well.  The good news is, your code looks pretty good and with a few tweaks I think we may be able to find a solution that should work.  Can you try a few tweaks for me and let me know how they go?

    First, make sure this is in your functions.php file:

    
    /**
     * Remove Ajax from The Events Calendar Pagination on List View
     * @3.8
     *
     */
    add_action('wp_print_scripts', 'events_calendar_remove_scripts' , 10);
    function events_calendar_remove_scripts() {
      wp_dequeue_script( 'tribe-events-list');
    }
    

    Next, try tweaking your spellerberg_* functions to make use of the tribe_get_listview_link() in place of any of the calls to tribe_get_past_link() and tribe_get_upcoming_link().  That function returns the List view URL used by the List view JS to build the previous/next Ajax requests.  My quick test of your functions with that change gave me some promising results!

    Does that help point you in the right direction?

    #953302
    Marty
    Participant

    tribe_get_listview_link() returns:

    /events/category/mycategory/list/

    In order to construct the URLs, it looks like the bast I need is:

    /events/category/mycategory/

    Is there a method that will output that?

    #953409
    Matthew
    Member

    The events_get_events_link() function should return the events link sans /list/. Let me know if that works for you!

    #953513
    Marty
    Participant

    Close, but not quite. It needs to have the current category slug in there, as applicable.

    #953692
    Matthew
    Member

    Whoops – sorry about that! Fetching that link isn’t something that we have in The Events Calendar as a single functionc all. However, you can retrieve that link using WordPress’ get_term_link() function in conjunction with our tribe_is_event_category() and tribe_meta_event_category_name() functions. With something like this:

    
    // default the link to the base events link
    $link = events_get_events_link();
    
    // if you're on a category page, fetch the base link for it
    if ( tribe_is_event_category() ) {
      $link = get_term_link( tribe_meta_event_category_name(), 'tribe_events_cat' );
    }
    

    Perhaps a bit more than what you were hoping, but it should do what you are looking to accomplish. Let me know how it goes!

    #955828
    Marty
    Participant

    Hi. Looks like we’re very close. One thing, though. This line:

    `$link = get_term_link( tribe_meta_event_category_name(), ‘tribe_events_cat’ );’

    get_term_link() wants either an object, ID or slug, but
    tribe_meta_event_category_name() returns the category name.

    What will give us the ID or slug? Thanks!

    #956114
    Matthew
    Member

    Well shoot, I guess I should have tested that code with a more realistic Event Category name. Sorry about that. Anyhow, give this approach that leverages $wq_query a shot:

    
    global $wp_query;
    
    // default the link to the base events link
    $link = events_get_events_link();
    
    // if you're on a category page, fetch the base link for it
    if ( tribe_is_event_category() && isset( $wp_query->query_vars['tribe_events_cat'] ) ) {
      $link = get_term_link( $wp_query->query_vars['tribe_events_cat'], 'tribe_events_cat' );
    }
    
    #960197
    Matthew
    Member

    It has been a while since we’ve traded messages so I’ll go ahead and close this thread for now. If you run into any other issues – feel free to open another thread!

Viewing 9 posts - 1 through 9 (of 9 total)
  • The topic ‘Non-AJAX navigation for List view’ is closed to new replies.