簡體   English   中英

無限滾動啟用(wordpress)

[英]infinite scroll enabling (wordpress)

所以,我發現本教程啟用無限滾動: http//wptheming.com/2012/03/infinite-scroll-to-wordpress-theme/

基本上我需要有js文件並將以下內容添加到function.php中

/**
 * 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 );

我需要更改以下參數:

  • img:ajax加載程序映像的路徑
  • nextSelector:“之前帖子”鏈接的選擇器。
  • navSelector:包含上一個/下一個導航鏈接的選擇器。
  • itemSelector:帖子的選擇器。 這可能是.hentry,.post,.etc
  • contentSelector:包含帖子的div。

好吧,我被卡住了。

這是我的PHP:

$defaults = array(
        'base' => add_query_arg( 'paged', '%#%' ),
        'format' => '',
        'total' => $max_num_pages,
        'current' => $current,
        'prev_next' => true,
        'prev_text' => __( '&larr;',my_site),
        'next_text' => __( '&rarr;',my_site), 
        'show_all' => false,
        'end_size' => 1,
        'mid_size' => 1,
        'add_fragment' => '',
        'type' => 'plain',
        'before' => '<div class="pagination">', 
        'after' => '</div>',
        'echo' => true,
        'use_search_permastruct' => true
  );

這是我目前得到的html輸出:

 <div class="pagination">
    <a class="prev page-numbers" href="example.com/dfgdg/page/2/">←</a>
    <a class="page-numbers" href="http://example.com/dfgdg/page/1/">1</a>
    <a class="page-numbers" href="http://example.com/dfgdg/page/2/">2</a>
    <span class="page-numbers current">3</span>
    <a class="page-numbers" href="http://example.com/dfgdg/page/4/">4</a>
    <span class="page-numbers dots">…</span>
    <a class="page-numbers" href="example.com/dfgdg/page/20/">20</a>
    <a class="next page-numbers" href="example.com/dfgdg/page/4/">→</a>
</div>

有人可以幫我解決這個問題嗎?

要么

我應該考慮采用不同的方法嗎?

謝謝一堆!

EM

基本上這里出現的問題是你在不理解底層代碼的情況下復制粘貼。

在您添加到PHP的JS片段中,您將添加無限滾動應該起作用的元素(contentSelector)

在示例中,它設置為“#content”,但在您的代碼中應該是“.pagination”。

所以,如果你改變contentSelector它應該工作:)

編輯:我建議您將php中的“之前”更改為id =“pagination”。 這可能會破壞您的模板,因此請確保使用不同的頁面對其進行測試,但這樣您就可以選擇id而不是更可靠,更快速的類

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM