【问题标题】:Any ideas on how to implement infinite scrolling on my Wordpress site?关于如何在我的 Wordpress 网站上实现无限滚动的任何想法?
【发布时间】:2014-12-06 06:49:35
【问题描述】:

我正在尝试在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”)。

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

【问题讨论】:

    标签: jquery css wordpress scroll infinite


    【解决方案1】:
    "nextSelector": ".load_more_cont",
    "navSelector": ".load_more_cont a",
    "itemSelector": ".home_post_box",
    "contentSelector": "#load_posts_container"
    

    【讨论】:

      猜你喜欢
      • 2010-12-02
      • 1970-01-01
      • 1970-01-01
      • 2011-03-23
      • 1970-01-01
      • 2015-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多