我正在尝试在我的图片说明中添加一些额外的信息。(参见我网站上的示例)我找到了一个插件,它为标题添加了一个额外的字段,并试图对其进行扩充以满足我的需要。
该插件是 Image Credit,它在图片上传器中添加了 2 行 - 一行用于源文本,另一行用于链接。我有另一个名为Media Tags的插件,可让您将标签应用于图像。在下面的函数中,我使用 $mt_terms 添加了媒体标签。
add_filter( 'img_caption_shortcode', 'wp_image_credit_img_caption_shortcode', 10, 3 );
function wp_image_credit_img_caption_shortcode($attr, $content, $html){
global $post;
$content = (object)$content;
$credit = wp_image_credit_get_credit_link(substr($content->id, strpos($content->id, "_") + 1));
$mt_terms = the_mediatags($post->id);
$result = <<<END
<div id="{$content->id}" class="wp-caption {$content->align}" style="width: {$content->width}px">{$html}</span><p class="wp-caption-text"> {$content->caption} <div style="float: right; width: 50%;"><p class="wp-caption-text"></br>$credit</p></div><div style="float: left; width: 50%;"><p style="font-size:12px"></br> tags: $mt_terms </style></p></div></div>
END;
return $result;
}
有什么建议吗?
@Filipe 我会走更多这条路:
add_filter( 'img_caption_shortcode', 'wp_image_credit_img_caption_shortcode', 10, 3 );
function wp_image_credit_img_caption_shortcode($attr, $content, $html){
global $post;
$content = (object)$content;
$credit = wp_image_credit_get_credit_link(substr($content->id, strpos($content->id, "_") + 1));
$mt_terms = 'Tags: ';
$tags = (array)wp_get_object_terms($post->ID, MEDIA_TAGS_TAXONOMY);
if ($tags) {
foreach($tags as $tag_item)
$mt_terms = $mt_terms . ',' . $tag_item->name;
}
else
$mt_terms = "postID: $post->ID";
$result = <<<END
<div id="{$content->id}" class="wp-caption {$content->align}" style="width: {$content->width}px">{$html}</span><p class="wp-caption-text"> {$content->caption} <div style="float: right; width: 50%;"><p class="wp-caption-text"></br>$credit</p></div><div style="float: left; width: 50%;"><p style="font-size:12px"></br> tags: coming soon! $mt_terms </style></p></div></div>
END;
return $result;
}