wordpress显示最新的一篇文章的缩略图和摘要,效果如图:
实现代码如下:
<div>
<?php query_posts(“showposts=1&cat=3″)?>
<?php while (have_posts()) : the_post(); ?>
<?php if ( get_post_meta($post->ID, ‘pre_image’, true) ) : ?>
<?php $image = get_post_meta($post->ID, ‘pre_image’, true); ?>
<a href=”<?php the_permalink() ?>”><img alt=”<?php the_title(); ?>” src=”<?php echo $image; ?>”></a>
<?php else: ?>
<a href=”<?php the_permalink() ?>”><img alt=”<?php the_title(); ?>” src=”<?php bloginfo(‘template_url’); ?>/files/wp30a.png”></a>
<?php endif; ?>
<h3><a title=”#” href=”<?php the_permalink() ?>”><?php the_title(); ?></a></h3>
<p><?php the_excerpt(); ?>…</p>
<?php endwhile; ?>
</div>
<hr>
<ul>
<?php query_posts(‘showposts=5&cat=11&offset=1′); while (have_posts()) : the_post(); ?>
<li><a href=”<?php the_permalink() ?>” title=”<?php the_title(); ?>” ><?php the_title(); ?></a><?php the_time(‘m-d’); ?></li>
<?php endwhile; ?>
</ul>
</div>