结合Wordpress插件功能

时间:2012-11-11 01:04:57

标签: image wordpress wordpress-plugin

我正在尝试在图片标题中添加一些其他信息。 (参见示例on my site)我发现了一个插件,为标题添加了一个额外的字段,我正在尝试增加它以满足我的需求。

该插件是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;
 }

1 个答案:

答案 0 :(得分:0)

不确定我理解你想要什么,但是在帖子中添加信息的最佳方法是使用自定义字段,稍后可以使用与此类似的代码阅读:

get_post_meta( $post->ID, 'MyCustomField1', TRUE );

希望得到这个帮助。

相关问题