Support » Plugin: WordPress Infinite Scroll - Ajax Load More » Help With Implementation

  • lechon

    (@lechon)


    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 dcooney

    (@dcooney)

    @lechon Here is the Implementation guide. This may help.
    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/

    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

    (@lechon)

    Hi @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.