0
我有一組'question/answer'div pairings,'answer'div隱藏並顯示'question'div被點擊的時間。該集合中的第一對應該加載已經打開的答案。在wordpress之外,這個按預期工作:http://jsfiddle.net/Y724r/1/:第一個孩子切換功能不像預期的那樣在wordpress循環中運行
當我把相同的代碼放入wordpress循環時,最後一個問題加載打開,而不是第一個:http://www.htcaz.com/web/?page_id=5(關於HTC的配對是'答案」 DIV應該是負荷開放,但這樣做,而不是最後一個)
循環:
<?php $subpages = new WP_Query("post_parent=5&post_type='page'&orderby=ID&order=ASC");
if($subpages->have_posts()) : while($subpages->have_posts()) : $subpages->the_post(); ?>
<div class="post">
<div class="question">
<?php the_title(); ?>
</div>
<div class="answer">
<?php the_content(); ?>
</div>
</div>
<?php endwhile; endif; ?>
的jQuery:
jQuery(document).ready(function() {
jQuery(".answer").hide();
jQuery(".question").click(function() {
jQuery(".answer").not(jQuery(this).next(".answer")).hide();
jQuery(this).next(".answer").toggle();
});
jQuery('.question:first-child').trigger('click');
});
是你搖滾!並特別感謝包括進一步閱讀的文檔鏈接:) – pixeloco
歡迎:) –