我认为这将是阿贾克斯的工作。我做了类似的事情来加载更多的帖子,基本上就是onclick、load content、append content(到现有元素)。
我还没有完全完成,但我认为这将给你一个良好的推动,朝着理想的方向。
首先,我们需要一个函数,当您单击它时,它可以满足您的需要。说明如所示this page. 如果你想让nopriv对访问者有用,请确保你也添加了nopriv。
function sd_get_more_posts() {
    // Handle request then generate response using WP_Ajax_Response
    // get posts
    $post_args = array(
        // your arguments
    );
    $more_posts = get_posts($post_args);
    // echo the output, in my case I use Timber, hence why the Timber::render
    Timber::render( \'partials/overview.twig\',
        array(
            \'modifier\' => $modifier,
            \'posts\'    => $more_posts
        )
    );
    // Don\'t forget to stop execution afterward.
    wp_die();
}
add_action( \'wp_ajax_more_load\', \'sd_get_more_posts\' );
add_action( \'wp_ajax_nopriv_more_load\', \'sd_get_more_posts\' );
 使用我的示例,您需要一个“加载更多帖子”类的链接。您需要将其添加到某个位置并将其排队。
jQuery(function($){
    jQuery(".load_more_posts").click(function(e) {
        e.preventDefault();
        // jQuery(this).addClass(\'hidden\'); // uncomment this to hide the trigger on click.
        // you might not need them, but they show a bit of what is possible.
        offset = jQuery(this).data(\'offset\');
        amount = jQuery(this).data(\'amount\');
        var data = {
            \'action\': \'more_posts\',
            \'offset\': offset,
            \'amount\': amount
        };
        jQuery.post(
            ajaxurl,
            data,
            function(response) {
                if (jQuery(response).find(\'.class-of-element\')){
                    var newElems = jQuery(response).find(\'.class-of-element\').html();
                    jQuery(\'.class-of-element\').append(newElems);
                }
            }
        );
    });
});
 希望这有帮助。