Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
4

add this before your other add_action call: add_action('wp_ajax_nopriv_zephyr_infinite_scroll', 'zephyr_get_nextpage'); the wp_ajax_ filter runs only when you are logged in. wp_ajax_nopriv_ runs only when logged out. This is so you can separate your requests, and maybe treat them differently, if that's the case. Check wp_ajax_(action)


4

Replace the above mytheme_render_infinite_scroll function with this: function mytheme_render_infinite_scroll() { while ( have_posts() ) : the_post(); if ('mytheme_portfolio' == get_post_type()) : get_template_part( 'content', 'archive-portfolio' ); else : get_template_part( 'content', get_post_format() ); ...


3

Update ... Here's the Final Code That Worked for Me This may not be perfect, but it seems to be working well for me with no errors. Feel free to add any suggestions for improvement if you have any. JS Code jQuery(document).ready(function($) { var count = 2; jQuery("#la-chooser").change(function() { loadArticlebyCat(this.value); }); ...


3

Your div wrapper is within your while loop, and split by your if clause. This cannot work properly, since your loop will generate up to 14 divs with the id ajax. Put the opening div tag after if ( $the_query->have_posts() ) { and the closing after wp_reset_postdata(); and you should be fine. Edit Are you sure, that you didn't miss any opening/closing ...


3

You've specified a priority of 1 for your pre_get_posts function here: add_action( 'pre_get_posts', 'mytheme_portfolio_archive_pages', 1 ); Jetpack doesn't specify a priority: add_action( 'pre_get_posts', array( $this, 'posts_per_page_query' ) ); So that gets added with the default priority for add_action, which is 10: $priority (int) (optional) ...


2

Your code is a bit complex, so I can't post a full-working code, but a proof of concept, then adapt to your code is up to you. So, Ajax in WordPress should be used via Ajax API, instead to send a request to same url, that of course print header, and other stuff, simply send a request via Ajax Api and output what you want. I assume that you have a code like:...


1

What if you remove the existing infinite-scroll before re-add it? remove_theme_support( 'infinite-scroll' ); add_theme_support( 'infinite-scroll', array( 'wrapper' => false, ) );


1

Found the code that works here: https://themeshaper.com/2013/10/08/how-to-override-jetpack-infinite-scroll-settings-in-a-child-theme/ /* * Change the posts_per_page Infinite Scroll setting from 10 to 20 */ function my_theme_infinite_scroll_settings( $args ) { if ( is_array( $args ) ) $args['posts_per_page'] = 20; return $args; } ...


1

You never seem to populate the $paged variable with a value. Try adding this before the query (from the codex): if ( get_query_var( 'paged' ) ) { $paged = get_query_var( 'paged' ); } elseif ( get_query_var( 'page' ) ) { $paged = get_query_var( 'page' ); } else { $paged = 1; } Also, your "load more" link has the page number hardcoded, so it will load the ...


1

This might not solve your problem, but it will help you in future to create custom queries. Paginating more than one query can get extremely tricky. By default the build in pagination in Wordpress don't have this logic to paginate multiple queries. You will have to run multiple queries and merge them in some way. OK, now to what I would like to point out. ...


1

You need to add the callback function in the argument list as part of the function call, rather than as part of the argument object: jQuery( infinite_scroll.contentSelector ).infinitescroll( infinite_scroll, function(){ addLazyLoad() } ); You can remove the function(){ addLazyLoad()} that's part of the infinite_scroll object (after "...


1

This is just one approach. You have the Load More button and once you click that you request for more posts via Ajax. You need to master Ajax in WordPress first and call WP_Query with specific arguments to fit your case. Once you get results via Ajax you need to use JavaScript or JQuery to inject that to the page. You can check Jetpack code if you are ...


1

Usually isotope allows appending new items and then just re-layout the masonry again: Somewhere in your JS file you should put the elements you want to append into a variable, e.g. new_elements jQuery('.grid').append(new_elements) .isotope('appended', new_elements) .imagesLoaded( function() { jQuery('.grid').istotope('layout'); }); ...


1

offset would skip posts, it sounds like you want the current page number * the number of posts per page- $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $posts_per_page = $paged * get_option('posts_per_page'); $args = array( 'posts_per_page' => $posts_per_page ); You'll need to keep in mind that total number of pages in the query object ...


1

WP_Query has a $post_count variable. http://codex.wordpress.org/Class_Reference/WP_Query#Properties Just pass that with the script using wp_localize_script


1

I'm assuming you want it to do what happens on Jetpacks' example without a button, just scroll down and more posts appear until there's no more? Not sure if this will help, but your code has the wrapper parameter set to false while Jetpack's example where they have the footer parameter section has it set to true: add_theme_support( 'infinite-scroll', array(...


1

As you already know you can use wp_ajax_* and wp_ajax_nopriv_* hook to handle ajax request. Let see it with an example how it works. First we need to pick a Unique action key for our ajax request. For now say my_action. It is good idea to prefixed the key with your plugin name, so it would not conflict with others. Now define two hook. wp_ajax_my_action and ...


1

I suppose the obvious alternative is having logic in content-page.php that checks to see if it's paged content and outputs differently if that's the case. Basically. In content-page.php: get_header(); //WordPress has a global variable for whether a post/page is paginated or not global $paged; // If post/page isn't paginated if ($paged === 0) { //Do ...


1

In order for this kind of effect to work, the jquery plugin needs to 'know' which html tag to insert additional post into as child elements. The loading is done using Ajax calls. If you look at the JetPak Infinite Scroll plugin doc page, it instructs you how to achieve this. In order for it to work out-of-the-box, your theme needs to be designed with ...


1

This is known bug. You can read something about this here: https://github.com/Yoast/wordpress-seo/issues/1109 michaelcurry there wrote a solution. Quick Fix - Put this into your functions file. add_action('wp_loaded', 'remove_actions'); function remove_actions() { remove_action( 'wp', array( $GLOBALS['wpseo_front'], 'pagination_overflow_redirect'...


1

As @Pieter Goosen said, you shouldn't be using query_posts, nor running your own query. Instead, override the main query that already runs: function wpse_144974_pre_get_posts( $wp_query ) { if ( ! is_admin() && $wp_query->is_main_query() && is_home() ) $wp_query->set( 'cat', 1 ); } add_action( 'pre_get_posts', '...


1

As per Milo, you need to read the query var page, but set the query var paged. Try this, $page = 0 == get_query_var('page') ? 1 : get_query_var('page'); $wp_query = new WP_Query( array( 'post__not_in' => array(get_the_ID()), 'category__not_in' => 9, 'post_type' => 'post', 'post_status' => 'publish', '...


1

When using pretty permalinks, the paged query var is for paginated archives, and the pretty permalink format is: http://example.com/category/foo/page/2/ The query var on paginated single posts is page, and the pretty permalink format is: http://example.com/post-name/2/ If you're trying to paginate a secondary loop using the current page number in a ...


1

Add <!--nextpage--> in your post editor to split your post.


Only top voted, non community-wiki answers of a minimum length are eligible