Title: Help With Implementation
Last modified: February 24, 2021

---

# Help With Implementation

 *  [lechon](https://wordpress.org/support/users/lechon/)
 * (@lechon)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/help-with-implementation/)
 * Hello,
 * I installed your plugin with the hopes that I could use the “Load More” function
   into an existing template that I have but I have not been able to executed it
   properly.
 * I already have a template called related.php which calls related category posts
   to every single post on the site. The template recognizes the category of each
   posts.
 * I wanted to add a “Load More” button at the end of the template to load the next
   round of related posts by category, but everything I have tried does not work,
   produces PHP errors or comes out in a garbage format.
 * The template I have works great, again all I want is to be able to insert a working
   code at the end of it that will allow your plugin to display a working “Load 
   More” button that will display another batch of related posts when you click 
   on it.
 * I hope you can help.
 * Here is a sample of the template code:
 *     ```
       <div class="relatedpost-container" role="navigation">
       <h2 class="relatedpoststitle"><?php printf( __('You are going to love these:', 'theme-nacho')) ?></h2> 				
   
       <?php
       //function to get related post having codition inside
       function get_related_post($postID){
   
       $tags = wp_get_post_tags($postID);
       $foundPosts = 0;
       $excludes=[$postID];
   
       if ($tags) {
       $tag_ids = array();
       foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
   
       $args=array(
       'tag__in' => $tag_ids,
       'post__not_in' => array($postID),
       'showposts'=>12,
       'ignore_sticky_posts'=>1
       );
   
       $my_query = new WP_Query($args);
       $foundPosts = $my_query->found_posts;
   
       if( $my_query->have_posts() ) {
       while ($my_query->have_posts()) : $my_query->the_post();
       $excludes[]=$my_query->post->ID; 
   
       get_template_part( 'loop', get_post_format() ); 
   
       endwhile;
       }
       wp_reset_query();}
   
       if ($foundPosts <12){
       $remainingPosts = 12- $foundPosts;
       get_category_posts($postID, $remainingPosts, $excludes);
       }
   
       }
   
       function get_category_posts($postID, $remainingPosts, $excludes){
   
       $catArgs = array(
       'category__in' =>  wp_get_post_categories($postID), 
       'showposts' => $remainingPosts,
       'post__not_in' => $excludes
       );
   
       $cat_post_query = new WP_Query($catArgs);
       $foundPosts = $cat_post_query->found_posts;
   
       if( $cat_post_query->have_posts() ) {
   
       while ($cat_post_query->have_posts()) : $cat_post_query->the_post();
       $excludes[]=$cat_post_query->post->ID; 
   
       get_template_part( 'loop', get_post_format() ); 
   
       endwhile;
       }
       wp_reset_query();
   
       if ($foundPosts < $remainingPosts){
       $stillRemaing = $remainingPosts-$foundPosts;
   
       get_latest_posts($excludes, $stillRemaing);}
        }
   
       function get_latest_posts($excludes, $stillRemaing){
   
       $latestPost = array(
       	'showposts' => $stillRemaing,
       	'post__not_in' => $excludes,
       	'post_type' => 'post',
       	'posts_per_page' => $stillRemaing,
       	'offset'=>0,
       	'orderby' => 'post_date',
       	'order' => 'DESC',
       	);
       $latest_post_query = new WP_Query($latestPost);
   
       if( $latest_post_query->have_posts() ) {
       while ($latest_post_query->have_posts()) : $latest_post_query->the_post(); 
   
       get_template_part( 'loop', get_post_format() ); 
   
       endwhile;
       }
       wp_reset_query();
       	}
   
       echo get_related_post($post->ID); ?>
   
       </div>
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Darren Cooney](https://wordpress.org/support/users/dcooney/)
 * (@dcooney)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/help-with-implementation/#post-14098801)
 * [@lechon](https://wordpress.org/support/users/lechon/) Here is the Implementation
   guide. This may help.
    [https://connekthq.com/plugins/ajax-load-more/docs/implementation-guide/](https://connekthq.com/plugins/ajax-load-more/docs/implementation-guide/)
 * Also, Ajax Load More offer archive page integration as found here.
    [https://connekthq.com/plugins/ajax-load-more/docs/archives/](https://connekthq.com/plugins/ajax-load-more/docs/archives/)
 * Ajax Load More is not as simple as just installing and you’re good to go.
    It
   takes a bit of configuration to build your query and render the template.
 * Hope this gets your started.
 *  Thread Starter [lechon](https://wordpress.org/support/users/lechon/)
 * (@lechon)
 * [5 years, 3 months ago](https://wordpress.org/support/topic/help-with-implementation/#post-14102354)
 * Hi [@dcooney](https://wordpress.org/support/users/dcooney/)
 * Thanks for the reply and information.
 * The plugin works right out the bat if you are are using shortcodes, and I guess
   this is great for small web sites.
 * Trying to implement this plugin into a site that has over 10,000 posts would 
   require to use the alm_render method, so the “Load More” button would display
   on every single post.
 * I am not a developer but I did tried my best using this method with no success.
 * After 10 hours of many, many, many tries, I have decided to abandon this plugin.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Help With Implementation’ is closed to new replies.

 * ![](https://ps.w.org/ajax-load-more/assets/icon-256x256.png?rev=2944639)
 * [Ajax Load More – Infinite Scroll, Load More, & Lazy Load](https://wordpress.org/plugins/ajax-load-more/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/ajax-load-more/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/ajax-load-more/)
 * [Active Topics](https://wordpress.org/support/plugin/ajax-load-more/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/ajax-load-more/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/ajax-load-more/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [lechon](https://wordpress.org/support/users/lechon/)
 * Last activity: [5 years, 3 months ago](https://wordpress.org/support/topic/help-with-implementation/#post-14102354)
 * Status: not resolved