is_date()

Sponsored Link

全ての日付ベースのアーカイブページが表示されている場合です。(例. 月、年、日、時間ベースのアーカイブ)

Sponsored Link

原文(翻訳元)When any date-based archive page is being displayed (i.e. a monthly, yearly, daily or time-based archive).

日付ベースの違い

誰かが日付順のサイトを参照するならば、異なる色を使用して別の年に投稿を区別してみましょう:

原文(翻訳元)If someone browses our site by date, let’s distinguish posts in different years by using different colors:

<?php
// this starts The Loop
if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2 id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
<?php the_title(); ?></a></h2>
<small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>

<?php
// are we showing a date-based archive?
if (is_date())
{
     if (date('Y') != get_the_date('Y'))
     {
          // this post was written in a previous year
          // so let's style the content using the "oldentry" class
          echo '<div class="oldentry">';
     } else {
          echo '<div class="entry">';
     }
} else {
     echo '<div class="entry">';
}
the_content('Read the rest of this entry »'); 
?>
</div>
Sponsored Link