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>
- The topic ‘Help With Implementation’ is closed to new replies.