我已经创建了用于在函数中创建短代码的函数。php。此函数如下所示
function related_category_sidebar() {
include_once(WP_PLUGIN_DIR.\'/sabai-directory/assets/templates/template_related_category.php\');
}
add_shortcode( \'related_category\', \'related_category_sidebar\' );
现在,我创建了自定义小部件侧栏,如:
add_action( \'widgets_init\', \'theme_slug_widgets_init\' );
function theme_slug_widgets_init() {
register_sidebar( array(
\'name\' => __( \'Related Category\', \'theme-slug\' ),
\'id\' => \'rel_cat\',
\'description\' => __( \'Widgets in this area will be shown on all posts and pages.\', \'theme-slug\' ),
\'before_widget\' => \'<li id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</li>\',
\'before_title\' => \'<h2 class="widgettitle">\',
\'after_title\' => \'</h2>\',
) );
}
现在,我在这里添加了文本小部件
Related category
小部件区域。然后,在我调用自定义文件中的小部件区域后,如下所示:
<?php dynamic_sidebar(\'rel_cat\'); ?>
但shorcode不起作用。这里,我用过
<?php echo do_shortcode(\'[related_category]\'); ?>
直接输入文件,使其正常工作。
但是,我想使用小部件区域的短代码,那么我应该在代码中更改什么呢?