Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Wordpress中的自定义函数上使用条件标记/if/else?_Wordpress_Function_Wordpress Theming_Thumbnails_Attachment - Fatal编程技术网

在Wordpress中的自定义函数上使用条件标记/if/else?

在Wordpress中的自定义函数上使用条件标记/if/else?,wordpress,function,wordpress-theming,thumbnails,attachment,Wordpress,Function,Wordpress Theming,Thumbnails,Attachment,如果没有附件,如何隐藏img标签 (函数来自本教程:) “/> 我需要这样的东西: <?php if ( get_attachment_picture()) { ?> <img src="<?php get_attachment_picture();?>"> <?php } else { ?> show nothing, not even av default image <?php } ?> "> 不显示任何内容,甚至不显示av

如果没有附件,如何隐藏img标签

(函数来自本教程:)

“/>
我需要这样的东西:

<?php if ( get_attachment_picture()) { ?>
<img src="<?php get_attachment_picture();?>">
<?php } else { ?>
show nothing, not even av default image
<?php } ?>

">
不显示任何内容,甚至不显示av默认图像

您可以让函数返回缩略图,而不是回显缩略图,从而完成所需的操作

从函数中删除以下行:

else:
    $related_thumbnail = "images/default_thumbnail.jpg";  //define default thumbnail, you can use full url here.
替换

echo $related_thumbnail;

然后,您的代码变为

<?php
$attachment = get_attachment_picture();

if ( ! empty($attachment) ) { ?>
    <img src="<?php echo $attachment; ?>">
<?php } ?>
可能值得删除它们,

如果您使用的是“标准”文章缩略图,您可以使用
has\u post\u缩略图


return $related_thumbnail;
<?php
$attachment = get_attachment_picture();

if ( ! empty($attachment) ) { ?>
    <img src="<?php echo $attachment; ?>">
<?php } ?>
ob_start();  
ob_end_clean();  
<?php 
//This must be in one loop

if(has_post_thumbnail()) {
    the_post_thumbnail();
} else {
    // if there is no thumbnail, do nothing (or whatever you want) here
}
?>