2011-10-03 191 views
0

我有一個wordpress主題,我必須創建一個有循環電影的頁面。 它有3個菜單點,可以在不重新加載頁面的情況下更改div文本。WordPress更改內容無需重新加載

到目前爲止沒有問題。

<a href="javscript:void(0);" onclick="getdata('text.php','content2');">Click here – put it in content box 2</a> 

但是,當我是個不同的頁面上,我點擊,例如第二個鏈接,就應該到視頻網頁和文本更改爲第二個。

我該怎麼做?

有沒有辦法做到這一點?

url/wordpressname/#1 
+0

您可以添加您的解決方案作爲一個答案,並標記爲「公認」。這樣的問題不會保持開放:) – ChrisH

+0

是的,我忘了,我仍然需要一天的時間來回答我自己的問題。謝謝你提醒我。 – dichterDichter

回答

0

找到了解決辦法:我在這裏找到了解決方案:http://www.deluxeblogtips.com/2010/05/how-to-ajaxify-wordpress-theme.html

,我改變了適合我的需要:

jQuery(document).ready(function($) { 
    var $mainContent = $("#text"), 
     siteUrl = "http://" + top.location.host.toString(), 
     url = ''; 

    $(document).delegate("a[href^='"+siteUrl+"']:not([href*=/wp-admin/]):not([href*=/wp-login.php]):not([href$=/feed/])", "click", function() { 
     //location.hash = this.pathname; 
     //return false; 
    }); 

    $("#searchform").submit(function(e) { 
     location.hash = '?s=' + $("#s").val(); 
     e.preventDefault(); 
    }); 

    $(window).bind('hashchange', function(){ 
     url = window.location.hash.substring(1); 

     if (!url) { 
      return; 
     } 


     if (url=="1") { 
      $mainContent.html('<p>Text1</>'); 
     } 

     if (url=="2") { 
      $mainContent.html('<p>Text2</>'); 
     } 

     if (url=="3") { 
      $mainContent.html('<p>Text3</>'); 
     } 

     if (url=="4") { 
      $mainContent.html('<p>Text4</>'); 
     } 


     // url = url + "#content"; 

     //$mainContent.animate({opacity: "0.1"}).html('<p>Please wait...</>').load(url, function() { 
      //$mainContent.animate({opacity: "1"}); 
     //}); 
    }); 

    $(window).trigger('hashchange'); 
}); 
相關問題