【发布时间】:2016-05-10 00:04:17
【问题描述】:
我创建信息簿框,其中类别为发布者,标签为流派。这是我的代码:
<table>
<?php
$my_publisher = get_the_category();
$my_genre = get_the_tags();
if( ! empty( $my_publisher[0] ) ) {
echo '<tr><td align="right" class="infobook"><b>Publisher</td><td align="center" class="infobook">:</td></b><td class="infobook"> <a href="'.get_category_link($my_publisher[0]->term_id ).'">'.$my_publisher[0]->cat_name.'</a></td></tr>';
}
if( ! empty( $my_genre ) ) {
echo '<tr><td align="right" class="infobook"><b>Genre</td><td align="center" class="infobook">:</td></b><td class="infobook"> ' .$my_genre. ' </td></tr>';
}
?>
</table>
作为发布者的类别是有效的,但作为流派的标签不起作用(不显示)。 我应该怎么做才能修复代码?
【问题讨论】:
-
我将此代码用于类别作为发布者:term_id ).'">'.$category[0]->cat_name.'' ; } ?>(来源:dbarnwal.wordpress.com/2014/07/23/…)。但是我还没有找到另一种显示标签的方法。
-
我查看了documentation,看起来它返回了一个对象数组,所以你不能像那样回显它。查看链接中的文档,了解他们如何使用
foreach并获取每个标签的名称。