我正在使用Multipostthumbnails插件-https://wordpress.org/plugins/multiple-post-thumbnails/
它有一个特定的命名约定。如果没有特征图像集,我知道输出占位符的常用方法,但不使用它们的代码?
我当然想要-
if ( has_post_thumbnail($post->ID) ){
$image = wp_get_attachment_image_src(get_post_thumbnail_id(), \'news-large\');
$image = $image[0];
echo \'<img src="\'.$image.\'" alt="" />\';
} else {
$image = get_template_directory_uri() .\'/assets/img/placeholders/placeholder.png\';
echo \'<img src="\'.$image.\'" alt="" />\';
}
但他们现有的显示特色图像的代码是-
if (class_exists( \'MultiPostThumbnails\' )) : MultiPostThumbnails::the_post_thumbnail(get_post_type(), \'header-image\', NULL, \'header-image-full\', array(\'class\' => "custom-header-image") ); endif;
只是看不到如何调整它以适应顶部的代码?
对于博客页面-
标准代码-
if (class_exists( \'MultiPostThumbnails\' )) : MultiPostThumbnails::the_post_thumbnail( \'page\', \'header-image\', get_option(\'page_for_posts\'), \'header-image-full\', array(\'class\' => "custom-header-image") ); endif;
我尝试显示占位符-
if ( class_exists( \'MultiPostThumbnails\' ) ) {
MultiPostThumbnails::the_post_thumbnail( \'page\', \'header-image\', get_option(\'page_for_posts\'),
\'header-image-full\',
array(\'class\' => "custom-header-image") );
} else {
$image = get_template_directory_uri() .\'/assets/img/placeholders/header_placeholder.png\';
echo \'<img src="\'.$image.\'" alt="" />\';
}
非常感谢
最合适的回答,由SO网友:Chinmoy Kumar Paul 整理而成
我认为您正在索引循环中添加代码。php或博客模板文件。您可能会尝试这样的事情:
if ( class_exists( \'MultiPostThumbnails\' ) &&
( MultiPostThumbnails::has_post_thumbnail( get_post_type(), \'header-image\' , get_the_ID() ) ) ) {
MultiPostThumbnails::the_post_thumbnail(get_post_type(), \'header-image\', NULL,
\'header-image-full\',
array(\'class\' => "custom-header-image") );
} else {
$image = get_template_directory_uri() .\'/assets/img/placeholders/placeholder.png\';
echo \'<img src="\'.$image.\'" alt="" />\';
}