我正在WordPress中为我的帖子缩略图添加一个自定义管理表列。
如果没有创建帖子缩略图,我想从主题图像目录中检索一个后备图像,并使用php而不包装html img标记。
所以我想我可以做echo get_template_directory_uri() .'/assets/images/geo.jpg';
,但这只是显示url。
我错过了什么?
代码:
...
function cpt_columns_content($column_id, $post_id) {
if ($column_id == 'last_modified') {
echo get_post_field('post_modified', $post_id);
}
else if ('post_thumbs') {
if (has_post_thumbnail()) {
// get the post featured thumbnail
the_post_thumbnail('xsm_thumbnail');
}
else {
// or else get from theme image directory
echo get_template_directory_uri() .'/assets/images/geo.jpg';
}
}
}
add_action('manage_program_posts_custom_column', 'cpt_columns_content', 10, 2);
post_thumbnail((返回完整的img标记html。您也必须打印标签,如以下代码:
function cpt_columns_content($column_id, $post_id) {
if ($column_id == 'last_modified') {
echo get_post_field('post_modified', $post_id);
}
else if ('post_thumbs') {
if (has_post_thumbnail()) {
// get the post featured thumbnail
the_post_thumbnail('xsm_thumbnail');
}
else {
// or else get from theme image directory
echo sprintf('<img src="%s" width="70px" height="70px" />',
get_template_directory_uri() .'/assets/images/geo.jpg');
}
}
}
add_action('manage_program_posts_custom_column', 'cpt_columns_content', 10, 2);