【发布时间】:2016-11-06 18:22:39
【问题描述】:
我对php的了解很少。
有什么方法可以在 wordpress 的 do_shortcode 函数中“放置当前页面 id”而不是特定的 id 编号?还是插件内部的文件问题?
<?php echo do_shortcode('[plugin-review id="2"]'); ?>
当我将此代码放入侧边栏时,我不想在我网站的每个页面上显示 id=2 页面的内容。
感谢您提供可能的解决方案。
编辑:我刚刚也发现了这个功能(有更多具有相同内容的功能)可能有用吗?
public function do_shortcode_ratings( $atts )
{
extract( shortcode_atts( array(
'id' => '',
'template' => '',
'post' => get_the_ID()
), $atts ) );
$shortcode = '[plugin-review id="'. $id .'" branch="ratings" post="'. $post .'" template="'. $template .'"]';
return do_shortcode( $shortcode );
}
【问题讨论】:
-
请出示您的代码。
-
很抱歉,我必须在发布前删除:/
-
你不能尝试:` $id = get_the_ID();'
-
好像不行:(