如果试图让Wordpress通过基于父母的子标题列表,但它的所有内容只是一个或两个标题。有什么建议吗?
以下代码
function get_categories_list() {
$parent = $child = array();
foreach (get_the_category(get_the_id()) as $cat) {
if ($cat->id === 0) {
continue;
}
if ($cat->category_parent === 0) {
array_push($parent,$cat);
} else {
array_push($child,$cat);
}
}
foreach ($parent as $key => $cat) {
if ($key !== 0) {
echo "-";
}
echo '<a href="' . get_category_link( $cat->category_parent ) .'"> ' . $cat->name . '</a>';
}
foreach ($child as $cat) {
if ($key !== 0) {
echo "-";
}
echo '<a href="' . get_category_link( $cat->category_parent ) .'"> ' . $cat->name . '</a>';
}
}
答案 0 :(得分:0)
foreach ($child as $cat) {
if ($key !== 0) {
echo "-";
}
echo '<a href="' . get_category_link( $cat->category_parent ) .'"> ' . $cat->name . '</a>';
}
应该是
foreach ($child as $key => $cat) {
if ($key !== 0) {
echo "-";
}
echo '<a href="' . get_category_link( $cat->category_parent ) .'"> ' . $cat->name . '</a>';
}