请帮助我在主题中的帖子内容之外执行一个短代码。我创建了一个插件,如下所示:
<?php
add_shortcode(\'jplayer\', \'embed_player\');
if (!is_admin()) {
add_filter(\'widget_text\', \'do_shortcode\');
}
add_filter(\'the_excerpt\', \'do_shortcode\', 11);
add_filter(\'the_content\', \'do_shortcode\', 11);
function embed_player($atts, $content = null) {
extract(shortcode_atts(array(
\'url\' => \'\',
\'autoplay\' => \'\',
\'volume\' => \'\',
\'class\' => \'\',
\'loops\' => \'\',
), $atts));
if (empty($url)) {
return \'<div style="color:red;font-weight:700;">ERROR!</div>\';
}
if (empty($volume)) {
$volume = \'80\';
}
if (empty($class)) {
$class = "player_container";
}
/** Set default container class */
if (empty($loops)) {
$loops = "false";
}
$parent_title = get_the_title( $post->post_parent );
/** check if the post has a Post Thumbnail assigned to it*/
if ( has_post_thumbnail() ) {
$thumbnail = the_post_thumbnail();
}
else {
$thumbnail = \'http://demo.link/i.jpg\';
}
$player_cont = \'<div class="\' . $class . \'">\';
$player_cont .= \'
<div id="player-1" class="light">
<div style="display:none;" class="playerData">
{"name":"\'.$parent_title.\'","size":{"width":"100%","height":"100%"},"media":{"mp3":"\' .$url.\'","poster":"\'.$thumbnail.\'"}}
</div>
</div></div>\';
return $player_cont;
}
上面的代码显示了帖子内容/条目中的音频播放器,但我想将此播放器作为格式添加到帖子标题中:
音频播放器(这里我想执行do_shortcode
功能)
帖子标题
帖子内容/条目(这里我包括了一个快捷码[jplayer url="http://my.link"]
)
为此,我插入了一个短代码[jplayer url="http://my.link"]
在post内容/条目中,并执行do_shortcode
在我这样的主题中:
<?php echo do_shortcode(\'[jplayer url="\'.$variable_parameter.\']\'); ?>
我还尝试了许多代码:
<?php echo do_shortcode(\'[jplayer url="\'.get_post_meta(\'post->ID\', \'url\', true).\'"]\') ?>
并尝试了
get_post_custom()
我是wordpress的初学者,所以我面临着很多问题,但我喜欢设计网站。请更正代码或指导我正确的方法。非常感谢。