wordpressいじり。
こういう、HTML関係の見た目いじりを僕は好き何だろなぁと今更ながら思ったりして。今いじってるWordPressは今のところ僕しか見ないのに、昨晩からずっといじってる(笑)
今朝はアーカイブ表示をした時のテンプレートを作ってる。
WPにはいくつかテンプレートファイルがあるけど、例えばカテゴリーアーカイブ表示した時には、category-x.php(xはカテゴリのID) > category.php > archive.php > index.phpの順に適用させてくとか。
他にもこう言う特別テンプレートはいくつかある。
- home.php
- ブログのトップページ(つまりホーム)のテンプレートとして使用。
- single.php
- 個別記事を表示するときのテンプレートとして使用。
- page.php
- WordPressのページ機能を利用して作成したページのページを表示するときのテンプレートとして使用。
- category.php
- 特定カテゴリのアーカイブを表示するときのテンプレートとして使用。
- author.php
- 特定の投稿者が書いた記事のアーカイブを表示するときのテンプレートとして使用。
- date.php
- 特定の日・月・年のアーカイブを表示するときのテンプレートとして使用。
- archive.php
- search.php
- 検索結果を表示するときのテンプレートとして使用。
- 404.php
今回はアーカイブページを選択した時にエントリがそのまま表示されるのではなく、タイトルがリスト表示するように変更した。参考にしたのは「http://developedtraffic.com/resources/wordpress-notes.php#catpage」。
index.phpにそこに書いてあるリストをコピペ。
<?php get_header(); ?> <div id="wrapper"> <div id="main"> <ul> <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?> <li id="catpost-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"> <?php the_title(); ?></a><br /> <?php the_excerpt() ?> <?php the_author() ?> ~ <?php the_date(''); ?> at <?php the_time() ?></li> <?php endforeach; else: ?> </ul> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <p><?php posts_nav_link(' — ', __('« go back'), __('keep looking »')); ?></p> </div> <?php include(TEMPLATEPATH."/left_sidebar.php");?> <?php include(TEMPLATEPATH."/right_sidebar.php");?> <?php get_footer(); ?>
これだと本文とタイトルが出るので、ちょっと改変。
<?php get_header(); ?> <div id="wrapper"> <div id="main"> <h3><u>Archive for the '<?php echo single_cat_title(); ?>' Category </u></h3> <dl class="archive_list"> <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?> <dt id="catpost-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"> <?php the_title(); ?></a></dt> <dd><li>by <?php the_author_posts_link(); ?>, on <?php the_date(''); ?> <?php the_time() ?></dd> <?php endforeach; else: ?> </dl> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <p><?php posts_nav_link(' — ', __('« go back'), __('keep looking »')); ?></p> </div> <?php include(TEMPLATEPATH."/left_sidebar.php");?> <?php include(TEMPLATEPATH."/right_sidebar.php");?> <?php get_footer(); ?>
じゃあ、リストのしたにエントリをいくつか表示!と思ったんだけど、これはうまく行かない。どうも、foreachの後だとhave_post()==nilになってしまうみたい。なんでだろ?
<?php get_header(); ?> <div id="wrapper"> <div id="main"> <h3><u>Archive for the '<?php echo single_cat_title(); ?>' Category </u></h3> <ul class="archive_list"> <?php if ($posts) : foreach ($posts as $post) : start_wp(); ?> <li id="catpost-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link: <?php the_title(); ?>"> <?php the_title(); ?></a> <?php endforeach; else: ?> </ul> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <h1><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1> <!-- entory Information --> <p class="details"> <img src="<?php bloginfo('template_directory'); ?>/images/calen.gif" alt="Posted On" /> <?php the_date(); ?> , <?php the_time() ?>, <img src="<?php bloginfo('template_directory'); ?>/images/who.gif" alt="By" /> <?php the_author_posts_link('nickname'); ?>, <img src="<?php bloginfo('template_directory'); ?>/images/comments.gif" alt="Comments Dropped" /> <a href="<?php comments_link(); ?>"> <?php comments_number('no responses','1 response','% responses'); ?> </a>, <?php edit_post_link('このエントリを編集'); ?> </p> <!-- entory Information --> <?php the_content(__('Read more'));?> <p class="detailsb"> » Filed Under <?php the_category(', ') ?> | <?php comments_popup_link('Leave a Comment', '1 Comment', '% Comments'); ?></p> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> <p><?php posts_nav_link(' — ', __('« go back'), __('keep looking »')); ?></p> </div> <?php include(TEMPLATEPATH."/left_sidebar.php");?> <?php include(TEMPLATEPATH."/right_sidebar.php");?> <?php get_footer(); ?>