我知道你在这里想干什么。而不是
return
在每个步骤中(您发现这些步骤不能正常工作),您应该创建一个名为
$output = "";
,然后代替每个
回来
,使用
.=
类操作员
$output .= '< new stuff ...>';
最后,在函数末尾
return $output;
返回您构建的HTML的完整字符串。
function compile_post_icons_legend_table() {
// Initialize a variable to build your output string
$output = "";
// Its starting value...
$output = '<div class="narrowed">
<h2 class="right-widget-title">Post Icons Legend</h2>
<table class="post-icons-legend">';
$terms = get_terms([
'taxonomy' => 'std_or_youtube',
'hide_empty' => false,
]);
foreach ( $terms as $term ) {
// Add to the string rather than return it
$output .= '<tr><td><div class="small-svg-icon-container"><svg><use width = "24" height ="24" xlink:href="https://www.ashenglowgaming.com/wp-content/plugins/wp-svg-spritemap-master/defs.svg#:'.$term->slug.'"></svg></div></td><td>'.$term->description.'</td></tr>';
}
$terms = get_terms([
'taxonomy' => 'content',
'hide_empty' => false,
]);
foreach ( $terms as $term ) {
// Again, add to it rather than return
$output .= '<tr><td><div class="small-svg-icon-container"><svg><use width = "24" height ="24" xlink:href="https://www.ashenglowgaming.com/wp-content/plugins/wp-svg-spritemap-master/defs.svg#:'.$term->slug.'"></svg></div></td><td>'.$term->description.'</td></tr>';
}
// Final closing html tags appended...
$ouptut .= '
</table>
</div>';
// Finally, return the whole HTML string you've built
return $output;
}