我想在另一个变量中的 HTML 中添加一个保存函数(无论是 WordPress 还是自定义函数)的变量。问题是,当我连接它时,它会弹出前端的 div 容器之外,我需要它在容器内。
例如此处显示的,我希望在这些 div 中生成“$stay_put”或 PHP:
function sort_sections( $sections ) {
$sections = explode(',', $sections);
$output = '';
/* $stay put needs to be able to hold any function */
$stay_put = wp_list_pages();
if ( empty( $sections ) ) {
return $output;
}
foreach( $sections as $section ) {
switch ( $section ) {
case 'section_a':
$output .= '<div>Section A</div>';
break;
case 'section_b':
$output .= '<div>Section B</div>';
break;
default:
break;
}
}
return $output;
}
我想出了但在容器外显示变量:
$stay_put
foreach( $sections as $section ) {
switch ( $section ) {
case 'section_a':
$output .= '<div>' . $stay_put . '</div>';
break;
case 'section_b':
$output .= '<div>' . $stay_put . '</div>';
break;
default:
break;
}
}
如果有人可以帮忙,
先感谢您。
呼啦一阵风