关于如何在我的Wordpress网站上实现无限滚动的任何想法?

时间:2014-10-11 03:02:19

标签: jquery css wordpress scroll infinite

我正尝试在http://lastmealifetime.com/处实现无限滚动到我的网站,从而替换页面底部的向下箭头。但是我遇到了一些麻烦。

我试过用这个:

/**
 * Load javascripts used by the theme
 */

function custom_theme_js(){
    wp_register_script( 'infinite_scroll',  get_template_directory_uri() . '/js/jquery.infinitescroll.min.js', array('jquery'),null,true );
    if( ! is_singular() ) {
        wp_enqueue_script('infinite_scroll');
    }
}
add_action('wp_enqueue_scripts', 'custom_theme_js');

/**
 * Infinite Scroll
 */
function custom_infinite_scroll_js() {
    if( ! is_singular() ) { ?>
    <script>
    var infinite_scroll = {
        loading: {
            img: "<?php echo get_template_directory_uri(); ?>/images/ajax-loader.gif",
            msgText: "<?php _e( 'Loading the next set of posts...', 'custom' ); ?>",
            finishedMsg: "<?php _e( 'All posts loaded.', 'custom' ); ?>"
        },
        "nextSelector":"#nav-below .nav-previous a",
        "navSelector":"#nav-below",
        "itemSelector":"article",
        "contentSelector":"#content"
    };
    jQuery( infinite_scroll.contentSelector ).infinitescroll( infinite_scroll );
    </script>
    <?php
    }
}
add_action( 'wp_footer', 'custom_infinite_scroll_js',100 );

/**
 * If we go beyond the last page and request a page that doesn't exist,
 * force WordPress to return a 404.
 * See http://core.trac.wordpress.org/ticket/15770
 */
function custom_paged_404_fix( ) {
    global $wp_query;

    if ( is_404() || !is_paged() || 0 != count( $wp_query->posts ) )
        return;

    $wp_query->set_404();
    status_header( 404 );
    nocache_headers();
}
add_action( 'wp', 'custom_paged_404_fix' );

但是我无法识别正确的CSS选择器(&#34; nextSelector&#34;,&#34; navSelector&#34;,&#34; itemSelector&#34;,&#34; contentSelector&#34;)对于我的特定主题。

对于我在这里可以做什么,有人有任何建议吗?

1 个答案:

答案 0 :(得分:0)

"nextSelector": ".load_more_cont",
"navSelector": ".load_more_cont a",
"itemSelector": ".home_post_box",
"contentSelector": "#load_posts_container"