【问题标题】:Wordpress jQuery update URL for Post Pagination用于发布分页的 Wordpress jQuery 更新 URL
【发布时间】:2014-01-03 02:02:37
【问题描述】:

我正在使用下面的代码来更新特定 div (postContent) 中 Wordpress 帖子的分页内容。它工作得很好,除了我希望根据我所在的内容页面更新 URL。就像您在没有此代码的情况下使用 wp_link_pages 时通常所做的一样。

谢谢

jQuery(function($) {
$('#content').on('click', '#pagination a', function(e){
    e.preventDefault();
    var link = $(this).attr('href');
    $('#content').fadeOut(500, function(){
        $(this).load(link + ' #content', function() {
            $(this).fadeIn(500);
        });
    });
  });
});

【问题讨论】:

    标签: jquery ajax wordpress pagination


    【解决方案1】:

    您可以使用 history.js 来操作它。

    (function(window,undefined){
    
        // Bind to StateChange Event
        History.Adapter.bind(window,'statechange',function(){ // Note: We are using statechange instead of popstate
            var State = History.getState(); // Note: We are using History.getState() instead of event.state
        });
    
        // Change our States
        History.pushState({state:1}, "State 1", "?state=1"); // logs {state:1}, "State 1", "?state=1"
        History.pushState({state:2}, "State 2", "?state=2"); // logs {state:2}, "State 2", "?state=2"
        History.replaceState({state:3}, "State 3", "?state=3"); // logs {state:3}, "State 3", "?state=3"
        History.pushState(null, null, "?state=4"); // logs {}, '', "?state=4"
        History.back(); // logs {state:3}, "State 3", "?state=3"
        History.back(); // logs {state:1}, "State 1", "?state=1"
        History.back(); // logs {}, "Home Page", "?"
        History.go(2); // logs {state:3}, "State 3", "?state=3"
    
    })(window);
    

    查看他们的 github 了解更多信息。

    history.js

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-10-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      • 2015-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多