2012-09-06 39 views
0

我在嘗試使用WordPress和實時鏈接時遇到了一些麻煩。實時鏈接中的jQuery和樣式

讓我解釋一下:

我在找到該鏈接被稱爲:

<a href="p?32" id="control">event 32</a> 

事件32這段代碼管理:

$.ajaxSetup({cache:false}); 


    $('#control').click(function(){ 
    var post_id = $(this).attr('href') 

    $('#calendar').animate({top:'-99em'},400, 
     function(){ 
     $(this).hide(); 
     $('#theEvent').fadeIn(400); 
     $('#theEvent').html('<div class="loading"></div>'); 
     $('#theEvent').load(post_id); 
     }); 
    return false; 

    }); 

,這完美的作品,內容這張單曲顯示如下:

a this is the single.php:

<div class="space"></div> 
<div class="clearfix"> 

    <?php the_post(); ?> 
    <div class="descritpion"> 
     <h2><?php the_title(); ?></h2> 
     <span><?php the_author(); ?></span> 
     <?php the_content(); ?> 
     <div class="center"> 
    <a href=# id="prev">Prev</a> 
    <a href=# id="next">Next</a> 
    </div> 
</div> 

<div class="gallery" > 
    <a href="/#fourth" id="close" class="close">X</a> 

    <div id="slideShow"> 
    <?php the_gallery(); ?> 

    </div> 

功能the_gallery()僅僅是一個帶有鏈接圖像的循環:<a rel="fancybox"><img/></a>

編輯:12年9月6日

畫廊功能的工作原理與attachments-plugin

function the_gallery() { 

    $attachments = attachments_get_attachments(); 
    $total_attachments = count($attachments); 

    if($total_attachments > 0) 
    { 
     for ($i=0; $i < $total_attachments; $i++) 

     { 
      $url = wp_get_attachment_image($attachments[$i]['id'], 
       'bullet-event'); 
      $lrgurl = wp_get_attachment_image_src($attachments[$i]['id'], 'large'); 




      echo ' 

      <a href="'.$lrgurl[0].'" 
      rel="#overlay" title="'.$attachments[$i]['title'].'"> 
      ' . $url . ' 
      </a> '; 


     } 
    } 

} 

單個.php裏面的jquery是:

var wrapEveryN = function(n, elements, wrapper) { 
    for (var i=0; i< elements.length; i+=n) { 
     elements.slice(i,i+n).wrapAll(wrapper); 
    } 
} 

wrapEveryN(12, $("#slideShow a"), '<div></div>'); 

$('#slideShow').cycle({ 
    fx:  'scrollLeft' 
}); 

問題就來了這裏,單裏面我要管理一個圖片庫(循環)一個的fancybox和風格......這正確顯示的唯一事情是樣式,但我不知道爲什麼js的不工作:

人我的代碼和插件都在plugins.php & main.php

+0

向我們展示你的js代碼(畫廊) – soju

+0

剛編輯,感謝 – Locke

回答

0

我假設你的js代碼是在一個現成的模塊,這樣就不會被執行2次。

試試這個,例如:

$('#theEvent').load(post_id, function(){ 
    wrapEveryN(12, $("#slideShow a"), '<div></div>'); 

    $('#slideShow').cycle({ 
    fx: 'scrollLeft'; 
    }); 
}); 

PS:你應該只加載page fragment

+0

謝謝你的提醒,我只是讓工作一切... – Locke