我正在尝试将变量$about
放在我要返回的html中...但是当我查看输出时,它会将$about
放在html代码之上......
function cc_shortcode( $atts ) {
$other_page = 498;
$about = the_field('cc_about_this_course', $other_page);
extract( shortcode_atts( array(
'id' => '',
), $atts) );
$result = '<div class="main">
<div class="accordion">
<div class="accordion-section">
<a class="accordion-section-title active" href="#accordion-1">ABOUT THIS COURSE<i class="fa fa-arrow-down"></i></a>
<div id="accordion-1" class="accordion-section-content open" style="display: block;">
<p>' . $about . '</p>
</div>
</div>
';
return $result;
}
答案 0 :(得分:1)
https://www.advancedcustomfields.com/resources/the_field/
the_field用于显示当前帖子中显示值的原因..
使用get_field的解决方案; https://www.advancedcustomfields.com/resources/get_field/
如果没有get_field ..(对于常见问题)......就像这样..
你可以ob_start();和ob_get_clean为你解决问题
function cc_shortcode( $atts ) {
$other_page = 498;
ob_start();
the_field('cc_about_this_course', $other_page);
$about = ob_get_clean();
extract( shortcode_atts( array(
'id' => '',
), $atts) );
$result = '<div class="main">
<div class="accordion">
<div class="accordion-section">
<a class="accordion-section-title active" href="#accordion-1">ABOUT THIS COURSE<i class="fa fa-arrow-down"></i></a>
<div id="accordion-1" class="accordion-section-content open" style="display: block;">
<p>' . $about . '</p>
</div>
</div>
';
return $result;
}