接上文:使用query_posts控制日志显示 – Wordpress主题Hack技巧(二)

Wordpress 最为让人着迷的功能之一就是定制区域(Custom Field)。 这项功能允许你在日志中附带展示除日志内容和概述以外的内容。通过区域定制, 你可以把Wordpress变成一个文章管理系统(CMS)。 比如我就使用了Custom Field这项功能来显示文章缩略图并通过这些缩略图链接到日志页面

要实现这项功能, 首先要在日志中添加custom field标签, 如下图

定制区域 - Custom Field

然后把下列代码放在主循环代码(the loop)中

<?php //get article_image (custom field) ?>
<?php $image = get_post_meta($post->ID, ‘article_image’, true); ?>
<a href=”<?php the_permalink() ?>”><img src=”<?php echo $image; ?>” alt=”<?php the_title(); ?>” /></a>

备注: Wordpress允许用户创建或者储存多个定制标签(key), 并在日志中多次重复使用

我在Best Web Gallery这个网站中通过定制区域功能成功的显示了站点缩略图,提示图, 以及相关链接。