<?php query_posts('arguments'); ?>
ループ内でクエリを変更するために使う。特定のカテゴリの記事を○件表示、といった時に使う最も使用頻度の高いタグではないかと思います。
詳細はここ。
これが、たまに悪さをします。 たとえば、下はindex.phpでかいてる、トップ用にNEWSカテゴリの記事を5件表示するものです。
<?php if (is_home () ) : ?>
<?php query_posts('cat=10&showposts=5'); ?>
<?php endif; ?>
<?php while (have_posts()) : the_post(); ?>
<div class="topPost">
<h3 class="topTitle"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<?php
$days=30;
$today=date('U');
$entry=get_the_time('U');
$sa=date('U',($today - $entry))/86400;
if( $days > $sa ){
echo " <span class="new">"."new!"."</span>";
}
?>
</h3>
<p class="topMeta"><?php the_time( get_option('date_format') ); ?></p>
<div class="topContent"><?php the_content('(continue reading...)'); ?></div>
</div> <!-- Closes topPost -->
<?php endwhile; ?>
それで、sidebar.phpのほうでは、こんな風に、もしもNEWSカテゴリーだった場合、月別記事を表示、としています。
<?php if (is_category('10')) { ?>
<!--NEWS ARCHIVES-->
<h2>MONTHLY ARCHIVES</h2>
<ul class="sidelist">
<?php wp_get_archives('cat=10'); ?>
</ul>
<!--NEWS ARCHIVES END-->
<?php } ?>
ところが、index.phpのほうでの、
<?php query_posts('cat=10&showposts=5'); ?>
をひきずってしまい、トップページなのに、サイドにこの月別記事が表示されてしまいます。
なので、こんなふうに、ループが終わったところで、 query_postsをクリアさせます。
<?php endwhile; ?> <!-- clear query_posts --> <?php query_posts($query_string); ?>
あと、index.phpのこれは、新着記事にNEW!マークをつけてます。30日間持続します。
<?php
$days=30;
$today=date('U');
$entry=get_the_time('U');
$sa=date('U',($today - $entry))/86400;
if( $days > $sa ){
echo " <span class="new">"."new!"."</span>";
}
?>
- Newer: BetweenAS3を使ってみた。
- Older: WordPressでサイト構築して便利だったプラグイン
Comments:0
Trackbacks:0
- Trackback URL for this entry
- http://blog.akuapa.com/wp-trackback.php?p=161
- Listed below are links to weblogs that reference
- WordPress 補足 from akuapa blog