我正在尝试为我的WordPress站点设置一个移动主题。我的桌面版使用的是Mejunkie的每周主题,而我的移动版使用的是dotmobi主题。
Dotmobi主题提取第一幅图像并显示为缩略图,其中每周主题将“特色图像”显示为缩略图或自定义字段值“thumb”中定义的图片
我怎样才能对dotmobi使用同样的逻辑呢?
我试过了get_thumbnail()
但这行不通。请帮忙。
我还尝试将此代码放入functions.php
// Get image attachment (sizes: thumbnail, medium, full)
function get_thumbnail($postid=0, $size=\'full\') {
if ($postid<1)
$postid = get_the_ID();
$thumb_key = get_theme_mod(\'thumb_key\');
if($thumb_key)
$thumb_key = $thumb_key;
else
$thumb_key = \'thumb\';
$thumb = get_post_meta($postid, $thumb_key, TRUE); // Declare the custom field for the image
if ($thumb != null or $thumb != \'\') {
return $thumb;
} elseif ($images = get_children(array(
\'post_parent\' => $postid,
\'post_type\' => \'attachment\',
\'numberposts\' => \'1\',
\'post_mime_type\' => \'image\', ))) {
foreach($images as $image) {
$thumbnail=wp_get_attachment_image_src($image->ID, $size);
return $thumbnail[0];
}
} else {
return get_bloginfo ( \'stylesheet_directory\' ).\'/images/default_thumb.gif\';
}
}
在我的index.php
通过<?php echo \'<a href="\'.get_permalink($post->ID).\'" rel="bookmark"><img src="\'.get_bloginfo(\'template_url\').\'/timthumb.php?src=\'.get_thumbnail($post->ID, \'full\').\'&h=\'.$height.\'&w=\'.$width.\'&zc=1" alt="\'.get_the_title().\'" /></a>\' ?>
出于某种奇怪的原因,缩略图没有显示出来