wordpress 不设置特色图像 默认调用图片
现在的网站文章列表不放点图片感觉总是少点什么,大部分的wordpress主题都是这样做的,当然你肯定想起了特色图片,在开发中调用一篇文章的特色图片很简单,只要用自带的函数
<?php the_post_thumbnail( $size, $attr ); ?>
那么如果我是个懒人怎么办,我的意思是写文章的时候懒得去设置特色图像,其实也好办
if (has_post_thumbnail()) { //如果设置了特色头像 默认用设置过了的 the_post_thumbnail(array(640, 115, ' uk-overlay-scale')); } else if ($images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image'))) { //如果没设置判断是否有图片 $image = current($images); $image = wp_get_attachment_image_src($image->ID, array(640, 115)); //图片的宽高 echo '<img class="uk-overlay-scale" src="' . $image[0] . '" />'; }
什么?你要问我为什么?
我是个懒人...
var_dump();
是个好工具...
admin
[哼] 有点像抽你的冲动 ..