Hatena::ブログ(Diary)

笑って進め RSSフィード

about / archive / antenna
 | 

20070617 Sun

wordpressいじり。

こういう、HTML関係の見た目いじりを僕は好き何だろなぁと今更ながら思ったりして。今いじってるWordPressは今のところ僕しか見ないのに、昨晩からずっといじってる(笑)

今朝はアーカイブ表示をした時のテンプレートを作ってる。

WPにはいくつかテンプレートファイルがあるけど、例えばカテゴリーアーカイブ表示した時には、category-x.php(xはカテゴリID) > category.php > archive.php > index.phpの順に適用させてくとか。

他にもこう言う特別テンプレートはいくつかある。


今回はアーカイブページを選択した時にエントリがそのまま表示されるのではなく、タイトルリスト表示するように変更した。参考にしたのは「WordPress Customization Notes」。

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(' &#8212; ', __('&laquo; go back'), __('keep looking &raquo;')); ?></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(' &#8212; ', __('&laquo; go back'), __('keep looking &raquo;')); ?></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"> &#187; 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(' &#8212; ', __('&laquo; go back'), __('keep looking &raquo;')); ?></p>
</div>

<?php include(TEMPLATEPATH."/left_sidebar.php");?>
<?php include(TEMPLATEPATH."/right_sidebar.php");?>
<?php get_footer(); ?>

スパム対策のためのダミーです。もし見えても何も入力しないでください
ゲスト


画像認証

トラックバック - http://d.hatena.ne.jp/allegro/20070617/1182046831
 |