2008年2月27日水曜日

WordPress アーカイブをリストで表示したい

サイドバーでアーカイブの年月を表示しているのは、
<?php //wp_get_archives('type=monthly'); ?>
type=monthlyで年月がでるなら
type=listとかなんとかできないないものか。

探したら、Main_PageのDesign and Layout
Template TagsのGeneral tagsに、wp_get_archives()の説明があった。


  1. 12ヶ月を表示するなら、
    <p><?php wp_get_archives('type=monthly&limit=12'); ?></p>

  2. 15日表示するなら、
    <p><?php wp_get_archives('type=daily&limit=15'); ?></p>

  3. 最後の投稿20個なら
    <p><?php wp_get_archives('type=postbypost&limit=20&format=custom'); ?></p>

  4. ドロップダウンボックスは
    <select name="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'>
    <option value=""><?php echo attribute_escape(__('Select Month')); ?></option>
    <?php wp_get_archives('type=monthly&format=option&show_post_count=1'); ?> </select>

と書いてある。
それぞれを、
<?php //wp_get_archives('type=monthly'); ?>
と入れ替えてみるとしっかり動く。

ということは、全部の記事をドロッブダウンさせるには、
<select name="archive-dropdown" onChange='document.location.href=this.options[this.selectedIndex].value;'>
<option value=""><?php echo attribute_escape(__('Select Month')); ?></option>
<?php wp_get_archives('type=postbypost&format=custom'); ?>
</select>
でいけるかも。


さっそくsidebar.phpの
<?php //wp_get_archives('type=monthly'); ?>
の場所に入れてみる。



<?php //wp_get_archives('type=postbypost&limit=20&format=custom'); ?>

<select name="archive_option" onChange='document.location.href=this.options[this.selectedIndex].value;'>
<option>Archives</option>
<?php wp_get_archives("format=option&type=postbypost"); ?>
</select>

こういう選択場所が現れた。

wp_get_archives2.png

ここで選ぶとそのページが表示される。
ごきげん!

0 件のコメント: