【发布时间】:2015-02-20 04:48:25
【问题描述】:
简而言之:我正在创建一个 WP 函数,它将根据以下条件回显图像 url
这里是条件语句的工作原理
如果存在自定义分类术语,则从自定义分类术语构建 img src url
elseif 自定义分类不存在 - 然后显示默认图像
存在其他自定义分类,但图像不可用。在外部 url 然后显示默认图片
这是我到目前为止所得到的,我无法完成第 3 步
我确实找到了这个解决方案:
function is_200(){
$urlimage = 'http://images.mysite.com/auto/mercedes-car.jpg';
if(@getimagesize($urlimage) !== false)
{
echo "HAVE image";
}
else
{
echo "Nop.";
}
}
但我无法让它与我的功能一起使用,如下所示
function cib_auto_thumbnail($width,$height) {
$timurl = "http://www.mywebsite.com/wp-content/plugins/timthumb.php?src=";
$thumburl ="http://images.mywebsite.com/auto/";
$defaultthumb ="http://images.mywebsite.com/auto/cib.jpg";
$thumburl2 =".jpg";
$timmake =""; $i = 1; foreach((get_the_terms( $post->ID, 'OriginalTag' )) as $timmakecat) {if ($timmakecat->parent == 0) {$timmake .= $timmakecat->name; if($i == 1) break;}} ;
$timmodel =""; $i = 1; foreach((get_the_terms( $post->ID, 'OriginalTag' )) as $timmodelcat) {if ($timmodelcat->parent |= 0) {$timmodel .= $timmodelcat->name; if($i == 1) break;}} ;
if (empty($timmake) || empty($timmodel)) {
echo '<img src="' . $timurl . $defaultthumb .'" / >';
// if no make or model i.e. custom taxonomy is blank; then get default image
// problem is a custom taxonomy can be created by the author - but the corrosponding image might not exist in the external file folder, hence I need the additional elseif to check for that
} else {
echo '<img src="' . $timurl . $thumburl . $timmake . '-' . $timmodel . $thumburl2 .'" / >';
// else get image from make and model custom taxonomy and create image url
}
**OriginalTags 是我的自定义分类术语的名称
*** 外部位置的每个图像都被适当命名为:make-model.jpg 即 $timmake-$timmodel.jpg
【问题讨论】:
标签: php wordpress function conditional