我需要一個循環來調用稱爲'團隊成員'的自定義帖子類型,它是'團隊'的slu g。團隊成員以五行顯示,每個成員包含自己的頭像,並在切換列表中的單獨DIV外側下拉切換內容。我已經寫出了一個基本的循環結構,我不確定它是否是最好的或正確的方法。有人能幫助我嗎?不同行上的循環內有多個循環
/* ROW 1 */
query_posts('showposts=5');
$ids = array();
/* Loop 1 A - displays the row of avatars */
while (have_posts()) : the_post();
$ids[] = get_the_ID();
the_title();
endwhile;
/* Loop 1 B - displays the slide down content in new row for each avatar above */
while (have_posts()) : the_post();
$ids[] = get_the_ID();
the_content();
endwhile;
/* ROW 2 */
//Write code to do second row if number posts greater than 5.
//If post greater than 5 do...
/* Loop 2 A - displays the row of avatars */
query_posts(array('post__not_in' => $ids, 'showposts=5');
while (have_posts()) : the_post();
the_title();
endwhile;
/* Loop 2 B - displays the slide down content in new row for each avatar above */
while (have_posts()) : the_post();
the_content();
endwhile;
/* ROW 3 */
//Write code to do third row if number posts greater than 15.
//If post greater than 10 do...
/* Loop 3 A - displays the row of avatars */
$ids_row_two = query_posts(array('post__not_in' => $ids));
$ids_row_three = query_posts(array('post__not_in' => $ids_row_three));
query_posts(array('post__not_in' => $ids_row_three, 'showposts=5'));
while (have_posts()) : the_post();
$ids[] = get_the_ID();
the_title();
endwhile;
/* Loop 3 B - displays the slide down content in new row for each avatar above */
while (have_posts()) : the_post();
$ids[] = get_the_ID();
the_content();
endwhile;
下面是HTML的結構我想輸出...
<!-- row 1 -->
<!-- Avatars -->
<div class="member_block">
<div class="container avatars">
<!-- avatar 1 --->
<div id="show_ryan" class="box five columns" data-target="#member_ryan">
<div class="avatar avatar-on-hidden">
<img src="<?php bloginfo('template_directory'); ?>/img/team/ryan.png">
<h4 class="name">Ryan</h4>
<p class="position">Creative Director</p>
</div>
<div class="avatar2 avatar-on-hover">
<img src="<?php bloginfo('template_directory'); ?>/img/team/ryan.jpg">
</div>
</div>
<!-- avatar 2 --->
<div id="show_brian" class="box five columns" data-target="#member_brian">
<div class="avatar avatar-on-hidden">
<img src="<?php bloginfo('template_directory'); ?>/img/team/brian.png">
<h4 class="name">Brian</h4>
<p class="position">Director</p>
</div>
<div class="avatar2 avatar-on-hover">
<img src="<?php bloginfo('template_directory'); ?>/img/team/brian.jpg">
</div>
</div>
<!-- avatar 3 --->
<div id="show_emma" class="box five columns" data-target="#member_emma">
<div class="avatar avatar-on-hidden">
<img src="<?php bloginfo('template_directory'); ?>/img/team/emma.png">
<h4 class="name">Emma</h4>
<p class="position">Creative Director</p>
</div>
<div class="avatar2 avatar-on-hover">
<img src="<?php bloginfo('template_directory'); ?>/img/team/emma.jpg">
</div>
</div>
<!-- avatar 4 --->
<div id="show_john" class="box five columns" data-target="#member_john">
<div class="avatar avatar-on-hidden">
<img src="<?php bloginfo('template_directory'); ?>/img/team/john.png">
<h4 class="name">John</h4>
<p class="position">Creative Director</p>
</div>
<div class="avatar2 avatar-on-hover">
<img src="<?php bloginfo('template_directory'); ?>/img/team/john.jpg">
</div>
</div>
<!-- avatar 5 --->
<div id="show_neil" class="box five columns" data-target="#member_neil">
<div class="avatar avatar-on-hidden">
<img src="<?php bloginfo('template_directory'); ?>/img/team/neil.png">
<h4 class="name">Neil</h4>
<p class="position">Creative Director</p>
</div>
<div class="avatar2 avatar-on-hover">
<img src="<?php bloginfo('template_directory'); ?>/img/team/neil.jpg">
</div>
</div>
</div><!-- container -->
<!-- each team member's slide down content -->
<div class="member_row">
<div class="container">
<!-- avatar 1 content --->
<div id="member_ryan" class="member-info">
<? the_content(); ?>
</div><!-- //Ryan -->
<!-- avatar 2 content --->
<div id="member_brian" class="member-info">
<? the_content(); ?>
</div>
<!-- avatar 3 content --->
<div id="member_emma" class="member-info">
<? the_content(); ?>
</div>
<!-- avatar 4 content --->
<div id="member_john" class="member-info">
<? the_content(); ?>
</div>
<!-- avatar 5 content --->
<div id="member_neil" class="member-info">
<? the_content(); ?>
</div>
</div><!-- .container -->
</div><!-- .member_row -->
<!-- row 2 -->
<!-- Avatars -->
<div class="member_block">
<div class="container avatars">
<!-- avatar 1 --->
<div id="show_ryan" class="box five columns" data-target="#member_ryan">
<div class="avatar avatar-on-hidden">
<img src="<?php bloginfo('template_directory'); ?>/img/team/ryan.png">
<h4 class="name">Ryan</h4>
<p class="position">Creative Director</p>
</div>
<div class="avatar2 avatar-on-hover">
<img src="<?php bloginfo('template_directory'); ?>/img/team/ryan.jpg">
</div>
</div>
<!-- avatar 2 --->
<div id="show_brian" class="box five columns" data-target="#member_brian">
<div class="avatar avatar-on-hidden">
<img src="<?php bloginfo('template_directory'); ?>/img/team/brian.png">
<h4 class="name">Brian</h4>
<p class="position">Director</p>
</div>
<div class="avatar2 avatar-on-hover">
<img src="<?php bloginfo('template_directory'); ?>/img/team/brian.jpg">
</div>
</div>
<!-- avatar 3 --->
<div id="show_emma" class="box five columns" data-target="#member_emma">
<div class="avatar avatar-on-hidden">
<img src="<?php bloginfo('template_directory'); ?>/img/team/emma.png">
<h4 class="name">Emma</h4>
<p class="position">Creative Director</p>
</div>
<div class="avatar2 avatar-on-hover">
<img src="<?php bloginfo('template_directory'); ?>/img/team/emma.jpg">
</div>
</div>
<!-- avatar 4 --->
<div id="show_john" class="box five columns" data-target="#member_john">
<div class="avatar avatar-on-hidden">
<img src="<?php bloginfo('template_directory'); ?>/img/team/john.png">
<h4 class="name">John</h4>
<p class="position">Creative Director</p>
</div>
<div class="avatar2 avatar-on-hover">
<img src="<?php bloginfo('template_directory'); ?>/img/team/john.jpg">
</div>
</div>
<!-- avatar 5 --->
<div id="show_neil" class="box five columns" data-target="#member_neil">
<div class="avatar avatar-on-hidden">
<img src="<?php bloginfo('template_directory'); ?>/img/team/neil.png">
<h4 class="name">Neil</h4>
<p class="position">Creative Director</p>
</div>
<div class="avatar2 avatar-on-hover">
<img src="<?php bloginfo('template_directory'); ?>/img/team/neil.jpg">
</div>
</div>
</div><!-- container -->
<!-- each team member's slide down content -->
<div class="member_row">
<div class="container">
<!-- avatar 1 content --->
<div id="member_ryan" class="member-info">
<? the_content(); ?>
</div><!-- //Ryan -->
<!-- avatar 2 content --->
<div id="member_brian" class="member-info">
<? the_content(); ?>
</div>
<!-- avatar 3 content --->
<div id="member_emma" class="member-info">
<? the_content(); ?>
</div>
<!-- avatar 4 content --->
<div id="member_john" class="member-info">
<? the_content(); ?>
</div>
<!-- avatar 5 content --->
<div id="member_neil" class="member-info">
<? the_content(); ?>
</div>
</div><!-- .container -->
</div><!-- .member_row -->
</div><!-- .member_block -->
你不需要做3個獨立的循環來獲得3行。在你的循環之前,初始化一個計數器,比如'$ x = 0;',然後每次迭代你會像$ x ++那樣增加$ x;然後你可以用if來檢查你是否是5的倍數$ x%5 == 0)'和裏面,如果把你的HTML結束/開始下一行。此外,當你在你的循環中,你可以寫出你的隱藏的div內容,使用該計數器給每個唯一的ID,然後使用JavaScript做隱藏/顯示。 – RightClick