ホーム > Yet Another Photoblog > 投稿記事のタイトルリストにサムネイルを付加

投稿記事のタイトルリストにサムネイルを付加

最新記事を除いた最近の記事を表示」の派生で、

update20071220

 このように、YAPBを用いて投稿記事のタイトルリストにサムネイルを付加します。

<?php
query_posts($query_string . "&category_name=blog&showposts=3&offset=1"; ) ;
if (have_posts()) :
?>
    <div id="recent_entries" class="post">
      <h3 class="title">Recent Entries</h3>
<?php
    while (have_posts()) : the_post();
?>
  <div class="post_simple" id="post-<?php the_ID(); ?>">
    <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php if ($post->image): $thumbnailConfig = array('h=50','w=50','fltr[]=usm|30|0.5|3','zc=1'); ?>
<img src="<?php echo $post->image->getThumbnailHref($thumbnailConfig) ?>" alt="<?php the_title() ?>" title="<?php the_title() ?>" width="<?php echo $post->image->getThumbnailWidth($thumbnailConfig) ?>" height="<?php echo $post->image->getThumbnailHeight($thumbnailConfig) ?>" class="pict_simple" /><?php else : ?>
<img src="<?php bloginfo('template_directory'); ?>/images/blog_icon.png" alt="Blog" width="50" height="50" class="pict_simple" /><?php endif ?>
<?php the_title(); ?></a></h3>
    <ul class="post-info">
      <li class="post-date"><?php the_time('Y/m/d(D) H:i') ?></li>
      <li class="post-cat"><?php the_category(' | ') ?></li>
      <?php the_tags('<li class="post-tag">Tags: ', ', ', '</li>'); ?>
      <li class="post-comments"><?php comments_popup_link('No Comments &#187;', '1 Comment &#187;', '% Comments &#187;'); ?></li>
    </ul>
  </div><!--/post -->
<?php endwhile; ?>
    </div>
<?php endif; ?>

 画像のない記事の場合は自分で用意した画像を使います。私の場合テンプレートフォルダ/images/ にある blog_icon.png を表示させていますので、コードはそのようになっています。カテゴリスラッグなども適宜読み替えてください。

 画像がない場合にカテゴリごとに振り分けてアイコンを変えるというのは、複数のカテゴリを選択していると難しいのでやってません。カテゴリを絶対にひとつしか設定しない自信があれば、さらにそういう振り分けをしてもいいかもですね。

※この記事は以下の記事に修正を加え再録したものです。
[Title] Yet another photoblog 導入メモ « Blog « LOVING CAT
[URL] http://lovingcat.net/2007/07/11/yapb-start-memo/

コメント:0

コメントフォーム
入力した情報を記憶する

トラックバック:0

この記事のトラックバック URL
http://web.lovingcat.net/add-thumbnail-to-titlelist/trackback/
トラックバックの送信元リスト
投稿記事のタイトルリストにサムネイルを付加 - LC Memo より

ホーム > Yet Another Photoblog > 投稿記事のタイトルリストにサムネイルを付加

検索
フィード
メタ情報

Return to page top