FAQ

Just another 仙台入門new weblog

­

最近の投稿:投稿内で使っている画像を、自動表示する

2009年 5月 29日 admin

投稿に利用している画像のサムネールを最近の投稿欄に、エントリーのマーカーとして添付するための、
コードサンプル

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
   <?php if(have_posts()): ?>
            <h2>Recent Post 10</h2>
            <ul>
              <?php while (have_posts()) : the_post(); ?>
              <li class="category<?php echo cat_id();?>">
<?php			
$images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent='.$post->ID);
			if ( empty($images) ) {/*画像を使っていない場合*/
			} else {
				foreach ( $images as $attachment_id => $attachment ) {
					echo wp_get_attachment_image( $attachment_id, "thumbnail");
					break;
				}
			}
?>
                <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?><?php the_time('Y年 F j日 '); ?>:<?php the_author(); ?>">
                <?php the_title(); ?>
                </a>
                <?php edit_post_link('Edit', '', '  ');      ?>  
 
              </li>
              <?php endwhile; ?>
            </ul>
   <?php endif;?>
.
© FAQ Entries (RSS) and Comments (RSS)