while ループで最初に出現する文字列を見つけようとする必要があります。回避できるのであれば、各要素の最初の要素を見つけるために Jquery を使用したくありません。
while ( $teacher_assignment_query->have_posts() ) {
$teacher_assignment_query->the_post();
$assignment_fields = get_post_custom($post->ID);
//print '$assignment_fields['title'][0] and stuff here
});
これは、このような割り当てのリストを出力します
<li class="assignments fourthgrade"><a href="#">Do worksheet 2-1</a></li>
<li class="assignments fourthgrade"><a href="#">Do worksheet 1-2</a></li>
<li class="assignments fourthgrade"><a href="#">Do worksheet 1-1</a></li>
<li class="assignments fifthgrade"><a href="#">Volunteer somewhere</a></li>
<li class="assignments fifthgrade"><a href="#">Finish science project</a></li>
5年生の前に4年生という順番です。またはループ内の各項目に対して$assignment_fields['grade'][0]
出力されます。fourthgrade
fifthgrade
それがいつ変化するかを見つける方法はありますか?最初はfourthgrade
とfifthgrade
です。したがって、上記のリストの代わりに、次のようなものを使用できます。
<li class="heading">Fourth Grade</li> //new heading
<li class="assignments fourthgrade"><a href="#">Do worksheet 2-1</a></li>
<li class="assignments fourthgrade"><a href="#">Do worksheet 1-2</a></li>
<li class="assignments fourthgrade"><a href="#">Do worksheet 1-1</a></li>
<li class="heading">Fifth Grade</li> //new heading
<li class="assignments fifthgrade"><a href="#">Volunteer somewhere</a></li>
<li class="assignments fifthgrade"><a href="#">Finish science project</a></li>