用于Post Pagination的Wordpress jQuery更新URL

时间:2014-01-02 17:55:58

标签: jquery ajax wordpress pagination

我正在使用下面的代码更新特定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);
        });
    });
  });
});

1 个答案:

答案 0 :(得分:0)

您可以使用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);

(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