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

标签 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 选择器(“nextSelector”、“navSelector”、“itemSelector”、“contentSelector”)。

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

最佳答案

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

关于jquery - 关于如何在我的 Wordpress 网站上实现无限滚动的任何想法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26310621/

相关文章:

php - WordPress 未在本地环境中运行,为 Google 应用引擎开发

javascript - <select> 上的 jQuery 更改事件未在 IE 中触发

javascript - 导航栏内的文本/ Logo 似乎在滚动时摆动/振动

wordpress 帖子页面规范

wordpress - 通过 register_widget 操作 Hook 将参数传递给 WP_Widget 构造

php - 用于更快加载的前端 UI

jQuery .post() 函数不适用于 Bootstrap

javascript - 确定数组的真值

html - 如何使我的图像尺寸固定但不影响/变形其外观?

html - 表格行前的分页符