Skip Navigation

[Resolved] Ajax load more for directory listings

This support ticket is created 5 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 20 replies, has 3 voices.

Last updated by Nigel 5 years, 3 months ago.

Assisted by: Nigel.

Author
Posts
#1349879

Hi Nigel,

I fixed that issue with the double quotes - I thought it was needed as the outer quotes were single but didn't realise it was within the Toolset shortcode so that didn't matter. I found another of these errors and after fixing it, the page fully loaded without pagination so that must have been what was causing the problem.

I've registered the custom sizes for the set images on the archive and regenerated the thumbnails. I'm now optimising all of the images on the site and will work though all of my styling bit by bit to see if there is something in either the functions file or stylesheets that are causing the slow down.

With the conditional statements - the icons are part of the supplied brand so not possible to compromise on. What I originally wanted to do was to inject the parent class into the body tag on all listings pages (eg: see-do, stay, eat-drink, shop etc...). That way I could just control the style with CSS but I couldn't figure out how to do that so the conditional queries were a work around. I didn't realise they would have a performance hit. I may need to find someone who can write the php to inject the parent class if that is possible.

I'm going to continue optimising and let you know how it goes! Thank you so much for your help on this - I really appreciate that you went above and beyond to troubleshoot it.

Kind Regards,
Orla

#1349997

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Orla

I'm not quite sure how adding body classes will help, but if you think it will I can probably help with the PHP snippet for that, there is a WordPress filter body_class for adding extra classes to the body.

But how should it know which classes to add, when?

#1350035

That would be brilliant! The icons and styles can't be added via CSS, the main issue was that I couldn't target the page title with a parent category class so I couldn't style them that way. Instead, I added the conditional statements in the views to display the classes - because of that there are a lot of conditional statements. If I could just target the class in the body, it would cut out a lot of the messing in the code.

The logic is:

If post = 'listing'
add parent category to the body class.

There are 6 parent categories: 'see-do', 'stay', 'eat-drink', 'shop', 'services', 'community'

Currently on the parent archive there is a class I could use - eg: hidden link - there is a class term-stay. However, when you go to the child archive it shows the child category (eg: term-hotel) - I would need it to also show the parent category (eg: term-stay term-hotel). Same for the single listing pages - their body class would also include 'term-stay'.

Is this possible to do?

#1350119

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Orla

It was fairly quiet this morning so I had a little time, although this is somewhat outside of the scope of support (which I mention solely so that anyone reading this understands we cannot always help crafting custom code).

This should work to add the parent term slug as a body class when visiting the taxonomy archives or visiting a single post that has terms from the taxonomy assigned.

You need to edit it for the post type and taxonomy:

function ts_filter_body_class( $classes ){

    $post_type = 'listing';
    $taxonomy = 'listing-category';

    if ( is_singular( $post_type ) ){
        global $post;
        $terms = get_the_terms( $post->ID, $taxonomy );

        foreach ($terms as $term) {

            if ( $term->parent == 0 ){
                $classes[] = $term->slug;
            }
        }        
    } elseif ( is_tax( $taxonomy ) ){

        global $wp_query;
        $query_obj = $wp_query->get_queried_object();
    
        if ( isset( $query_obj->term_id ) ) {
    
            $term = $query_obj;
            
            // iterate to top-level term as required
            while ( $term->parent != '0' ) {
                $parent_id = $term->parent;
                $term = get_term( $parent_id, $taxonomy);
            }
    
            $classes[] = $term->slug;
        }
    }
    
    return $classes;
}
add_filter( 'body_class', 'ts_filter_body_class' );
#1350501

Well that just knocked my socks off - you are a php wizard, it worked perfectly! Thank you so much - I now have a weekend of simplifying my css and views - hopefully that will speed things up a little :-)! Will report back to let you know what speed I can get it down to.

Thank you so much again - I really appreciate that this is way above and beyond general support :-).

Kind Regards,
Orla

#1351469

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Good luck, let me know how you get on.