【发布时间】:2018-05-07 17:15:17
【问题描述】:
我想在 WordPress 中围绕 get_template_part('path/file') 包装一个打开和关闭简码函数。它不是在 HTML 输出中环绕代码,而是显示在内容下方。
下面的例子:
PHP 输出:
<?php
function get_products($atts = [], $output = null) {
PHP outout:
$output= get_template_part('partials/modules/content', 'fields');
$output .= '[shortcode]'. $output .'[/shortcode]';
$output .= ob_get_clean();
return $output;
}
add_shortcode('resources', 'get_products');
?>
<?php echo do_shortcode('[resources]'); ?>
HTML 输出:
<div class="content">
</div>
<div class="shortcode">
</div>
HTML 所需的输出:
<div class="shortcode">
<div class="content">
</div>
</div>
【问题讨论】:
-
请阅读Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - 总结是这不是解决志愿者的理想方式,并且可能会适得其反。请不要将此添加到您的问题中。
-
是的,我的意思是。输出。抱歉打错了。
标签: php wordpress templates shortcode