【发布时间】:2018-05-31 07:34:10
【问题描述】:
目的是生成一个 html 表,其中包含 WordPress 函数 get_terms 检索到的信息。它创建一个表格图标图例,并以 html 形式呈现。在这里,我正在创建一个短代码,以便在需要时调用此函数。
但是,对于 PHP 编程新手,我不知道如何正确实现这一点,因为我在 PHP 编程中面临一个函数无法返回多个值的约束。请修改以下代码以实现其意图,我相信这是清楚的,即使代码无效。
<?php
// Custom function to compile post icons legend table - added by you 18 Dec 2017
function compile_post_icons_legend_table() {
return'<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 ) {
return '<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 ) {
return '<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>';
}
return
'</table>
</div>';
}
add_shortcode('post_icons_legend_table', 'compile_post_icons_legend_table');
?>
【问题讨论】: