• I have a theme which includes a “load more” function – but when it’s click it loads the same posts a second time rather than the next posts.

    my blog: https://braisedandconfused.com/

    I’ve identified the load more function in “functions.php”

    I can’t figure out which variable I have to play with to resolve this issue?

    thanks!

    function load_content_init($query) {
    		$max_pages = $query->max_num_pages;
    		$posts_count = $query->found_posts;
    		$posts_per_page = $query->post_count;
    		$page = ( get_query_var('paged') > 1 ) ? get_query_var('paged') : 1;
    
    		?>
    		<script>
    		jQuery(document).ready(function($) {
    			var max_pages = parseInt('<?php echo $max_pages; ?>');
    			var posts_count = parseInt('<?php echo $posts_count; ?>');
    			var posts_per_page = parseInt('<?php echo $posts_per_page; ?>');
    			var page = parseInt('<?php echo $page; ?>') + 1;
    			var next_page_link = '<?php echo next_posts($max_pages, false)?>';
    
    			var $button = $('#gentle-lm-button');
    			var $container = $("#mpc-page-content");
    			var $loaded = $('#gentle-lm-info');
    
    			$loaded.text(posts_per_page + ' / ' + posts_count);
    
    			if(posts_count <= posts_per_page)
    				$button.hide();
    
    			$button.click(function() {
    
    				if (page <= max_pages) {
    					$(this).text('Loading...');
    
    					$('<div></div>').load(next_page_link + ' .post', function() {
    						var $posts = $(this).children();
    
    						page++;
    						next_page_link = next_page_link.replace(/page\/[0-9]\//, 'page/' + page);
    
    						if (page <= max_pages) {
    							$button.text('Load More');
    							$loaded.text((posts_per_page * (page - 1)) + ' / ' + posts_count);
    						} else {
    							$button.stop().animate({ 'top': '30px' }, 500, 'easeOutExpo', function() {
    								$(this).hide();
    							});
    							$loaded.text(posts_count + ' / ' + posts_count);
    						}
    
    						$container.append($posts);
    						$posts.addClass('no-transition');
    						$posts.css( { 'opacity' : 0 });
    
    						if ($.browser.msie && parseInt($.browser.version, 10) === 8) {
    							$container.isotope('addItems', $posts, function() {
    								$(window).trigger('resize');
    
    								$posts.animate({ 'opacity' : 1}, 2000, 'easeOutExpo', function() {
    									$posts.removeClass('no-transition');
    								});
    							});
    						}
    						else {
    							$container.imagesLoaded(function() {
    								$container.isotope('addItems', $posts, function() {
    									$(window).trigger('resize');
    
    									$posts.animate({ 'opacity' : 1}, 2000, 'easeOutExpo', function() {
    										$posts.removeClass('no-transition');
    									});
    								});
    							});
    						}
    
    						setTimeout(function(){
    							$(window).trigger('resize');
    						}, 200);
    
    						$(window).trigger('resize');
    					});
    				}
    			});
    		});
    		</script>
    <?php }
    
    add_action('mpc_post_loop', 'load_content_init');


    [blockquote is not a code button – please use the correct button as your code may get corrupted otherwise ]

Viewing 1 replies (of 1 total)
  • Have you asked the developers/vendor of your theme? Commercial themes aren’t supported on these forums.

Viewing 1 replies (of 1 total)
  • The topic ‘Load More Button loads the same posts over again’ is closed to new replies.