简而言之:我正在创建一个WP函数,它将根据以下条件回显图像URL
这里的英文是条件应该如何工作
如果存在自定义分类术语,则从自定义分类术语构建img src 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
答案 0 :(得分:0)
<?php
$terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy' => 'taxonomy_name') );
$terms = apply_filters( 'taxonomy-images-get-terms', '', array('taxonomy'=>'features', 'image_size' => 'details', 'term_args' => 'hide_empty=0', 'order' => 'ASC' , 'orderby' => 'title', 'count' => 2) );
foreach($terms as $term){
echo '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . wp_get_attachment_image( $term->image_id, 'thumb' ) . '</a>';
?>