当我没有在自定义字段中添加图片时,如何检索图片,比如说(没有图片)
我使用此代码检索字段。。。
<img class="film"
src="/scripts/timthumb.php?src=<?php the_field(\'img_actor\'); ?>&h=251&w=175&zc=1"
alt="<?php the_title(); ?>"
title="<?php the_title(); ?>"/>
如何从此代码中检索无图片
<?php
if(get_field(\'distributie\') != ""){$counter=0;foreach(get_field(\'distributie\') as $post_object): ?>
<div class="act-box">
<a href="<?php echo get_permalink($post_object->ID); ?>" title="Actor <?php echo get_the_title($post_object->ID) ?>">
<img class="actor_img" src="/scripts/timthumb.php?src=<?php echo get_field( \'img_actor\', $post_object->ID ); ?>&h=70&w=50&zc=1" alt="<?php echo get_the_title($post_object->ID) ?>" title="<?php echo get_the_title($post_object->ID) ?>" /></a>
<span class="act-titlu">
<a href="<?php echo get_permalink($post_object->ID); ?>" title="Actor <?php echo get_the_title($post_object->ID) ?>"><?php echo get_the_title($post_object->ID) ?></a>
</span>
</div>
<?php $counter++;if($counter>=8) break; endforeach;}?>
如果我改变
<?php echo get_field( \'img_actor\', $post_object->ID ); ?>
使用
<?php echo urlencode($img); ?>
我得到一个错误($post\\u object->ID),我应该把它放在哪里?
SO网友:Wyck
下面是我用于图像冗余的内容。
1、首先尝试获取特色图像。然后是贴在帖子上的第一张图片。然后是默认图像。
$attachments = get_children(
array(
\'numberposts\' => 1,
\'order\'=> \'ASC\',
\'post_mime_type\' => \'image\',
\'post_parent\' => get_the_ID(),
\'post_status\' => null,
\'post_type\' => \'attachment\'
));
//first check for featured image
if ( has_post_thumbnail() ) {
the_post_thumbnail(\'thumbnail\');
//no featured image get first attachment
} elseif ($attachments) {
$first_attachment = reset($attachments);
echo wp_get_attachment_image($first_attachment->ID, \'thumbnail\');
} else {
echo \'<img src="../something/default.jpg"\';
}
附言:如果你想的话,你可以在里面插入破烂的timthumb,或者第四次检查你的自定义
get_field(\'img_actor\')