因此,我有以下标记来显示一个短代码:
<div class="my_edit_button">
<?php echo do_shortcode(\'[something]\'); ?>
</div>
然后,我试图通过使用以下代码,使快捷代码仅显示给post author:return ($post->post_author == $current_user->ID);
但我不知道如何将两者结合在一起。有人能帮帮我吗?
非常感谢!
因此,我有以下标记来显示一个短代码:
<div class="my_edit_button">
<?php echo do_shortcode(\'[something]\'); ?>
</div>
然后,我试图通过使用以下代码,使快捷代码仅显示给post author:return ($post->post_author == $current_user->ID);
但我不知道如何将两者结合在一起。有人能帮帮我吗?
非常感谢!
Try this
<div class="my_edit_button">
<?php if ( $post->post_author == $current_user->ID ) {
echo do_shortcode(\'[something]\');
}?>
</div>
一个更简洁的解决方案是将所有逻辑和标记封装到短代码本身中:
function conditional_shortcode_wpse_188037() {
global $post;
if ( $post->post_author == get_current_user_id() ) {
$ret = \'<div class="my_edit_button">\';
$ret .= \'other shortcode content\';
$ret .= \'</div>\';
return $ret;
}
}
add_shortcode(\'something\',\'conditional_shortcode_wpse_188037\');
我正在尝试使用wp\\u localize\\u脚本将一些变量(帖子的作者、帖子的类别和帖子的标题)传递给js文件。我不能,因为我的生活得到这些正确的。如何获取当前正在查看的帖子的相关数据?当前代码:wp_enqueue_script( \'stats\', get_stylesheet_directory_uri() .\'/js/t5-demo.js\' , array( \'jquery\' ), \'1.0.0\', true ); $categories = implode(