2011-10-03 113 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'); 
}); 
相关问题