特定の数毎に折り返してページをリストにできる WordPress のコード書いておきました。ページフッタなどでご利用くださいませ。
使い方
以下のように書くとそこにページリストを出力します。この例だと10個出力すると折り返します。
1 | <?php wbsPageList(10); ?> |
使うための準備
functions.php にこのコードを貼りつければ終わりです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | function wbsPageList($turnPoint = 10, $showpost = 100) { $loop = new wp_query(); $loop->query('post_type=page&orderby=post_title&order=DESC&showpost=' . $showpost . '&posts_per_page=' . $showpost); $count = 0; $onceflug = false; while($loop->have_posts()) { $loop->the_post(); if($count % $turnPoint == 0) { if($count == 0) { echo '<ul class="pagelist list-start">'; } else if((count($loop->posts) - $count) < $turnPoint) { echo '<ul class="pagelist list-end">'; } else { echo '<ul class="pagelist">'; } } echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>'; if($count % $turnPoint == $turnPoint - 1) { $onceflug = true; echo '</ul>'; } $count++; } if(!$onceflug) { echo '</ul>'; } } |
コメント