我想做的是在内容之后和插件之前输出一个自定义字段内容(这是一个带有动态链接的按钮,插入到每个帖子的自定义字段的值中)。
这是自定义字段的代码:
<div class="button">
<a href="<?php echo get_post_meta($post->ID, \'Button\', true); ?>">
<img src="<?php echo get_template_directory_uri() . \'/images/button.png\'; ?>" alt="link" />
</a>
</div>
在wordpress codex上,我还找到了如何对\\u内容应用过滤器以获得类似于我所需内容的示例。代码如下:add_filter( \'the_content\', \'my_the_content_filter\', 20 );
/**
* Add a icon to the beginning of every post page.
*
* @uses is_single()
*/
function my_the_content_filter( $content ) {
if ( is_single() )
// Add image to the beginning of each page
$content = sprintf(
\'<img class="post-icon" src="%s/images/post_icon.png" alt="Post icon" title=""/>%s\',
get_bloginfo( \'stylesheet_directory\' ),
$content
);
// Returns the content.
return $content;
}
问题是我不懂PHP,也不知道如何编辑上述代码以应用于我的具体案例。