使用WordPress的内置“功能的图像”(可交的编辑页面上的WordPress管理设置)。
在网页上显示的摘录:
<div id="excerpts">
<?php
$args = array('numberposts' => 3, 'category'=> '1,3,5'); }
// set number of excepts to show
// and optionally restrict to certain categories
$posts = get_posts($args);
foreach($posts as $post) : setup_postdata($post);
?>
<div class="single-excerpt">
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<?php if (has_post_thumbnail()) the_post_thumbnail('excerpt-thumb'); ?>
<!-- displays thumbnail if it exists -->
<p><?php the_excerpt();?></p>
</div><!-- single-excerpt -->
<?php endforeach; ?>
</div><!-- excerpts -->
在你的主题的的functions.php:
if (function_exists('add_image_size')) add_theme_support('post-thumbnails');
if (function_exists('add_image_size')) {
add_image_size('excerpt-thumb', 0, 100, false);
// define excerpt-thumb size here
// in the example: 100px wide, height adjusts automatically, no cropping
}
function new_excerpt_length($length) {
return 42;
// define length of excerpt in number of words
}
add_filter('excerpt_length', 'new_excerpt_length');
所以我可以有一个单独的主页上有多个职位,每个职位将有自己的特色图像,是吗? – mgPePe 2011-05-23 19:28:19
是的,没错。上面的代码将产生完全的。只有'the_excerpt()'的警告是它没有格式化。如果你想要段落的文章摘录,你必须改用'the_content()'和'more'标签。 – 2011-05-23 20:16:55
我将它标记为正确,但我想出了一个不同的方式:'add_theme_support('post-thumbnails');'在函数中,然后'<?php the_post_thumbnail();?>在循环中执行作业 – mgPePe 2011-05-27 13:46:46