以编程方式在多个页面中调用多个短代码

问题描述

我有两个短代码,如下所示:

function callback_func1($atts){
ob_start();
include(locate_template('name_of_php_file.php'));
return ob_get_clean();
}
add_shortcode('name_of_php_file','callback_func1');

function callback_func2($atts){
ob_start();
include(locate_template('name_of_another_php_file.php'));
return ob_get_clean();
}
add_shortcode('name_of_another_php_file','callback_func2');

现在,我有一个博客页面小部件简码,其中包含诸如[name_of_another_php_file title="Style" sub-title="need?"]之类的字段,我想从中将titlesubtitle渲染到我的主home.php文件中。

怎么做?

我在home.php中尝试了以下代码,但是它不起作用。

<h2 class="main-title thx"><?php echo sanitize_text_field($atts['title']) ?></h2>

<p class="sub-title drb"><?php echo sanitize_text_field($atts['sub-title']) ?></p>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)