DocumentationOnline documentation for Ajax Load More
Related Posts
The code below will display a list of related content based on the selected categories of the current post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<?php // single.php get_header(); ?> <?php the_title('<h1>', '</h1>'); ?> <?php the_content(); ?> <hr/> <?php // Related Posts $terms = get_the_category($post->ID); // get current categories $term_array = []; // Create empty category array foreach( $terms as $term ) { // Loop founf categories $term_array[] = $term->slug; } // Render Ajax Load More shortcode echo do_shortcode('[ajax_load_more category="'. implode(",", $term_array) .'" post__not_in="'. $post->ID .'"]'); ?> <?php get_footer(); ?> |
Note: This can also be used for tags and custom taxonomies by replacing get_the_categories() with the appropriate function.