我凭借对php的一点知识打了一堵墙。
有没有办法如何"把当前页面ID"而不是wordpress中的do_shortcode函数中的特定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 );
}
答案 0 :(得分:2)
当前的帖子/页面ID可通过全局$post
变量获得,即
global $post;
$current_id = $post->ID;
现在您可以在短代码中使用$current_id
:)
答案 1 :(得分:0)
你可以关注,这一个
global $post;
$current_id = $post->ID;
echo do_shortcode('[plugin-review id="'.$current_id.'"]');