我正在努力实现这样的目标:
A:
父类别以
子类别另一个父类别,以
子类别B:
父类别以B开头
子类别子类别。。。等
我很难找到这样的插件,我找到的插件不是很好。我也不能自己编写代码,因为我只有有限的PHP知识。
但我确实遇到了以下片段:
$list = \'\';
$cats = get_terms(\'category\');
$groups = array();
if( $cats && is_array( $cats ) ) {
foreach( $cats as $cat ) {
$first_letter = strtoupper( $cat->name[0] );
$groups[ $first_letter ][] = $cat;
}
if( !empty( $groups ) ) {
{
$index_row .=\'<ul>\';
foreach ($groups as $letter => $cats) {
$index_row .= \'<li><h4><a href="#\' . $letter . \'" title="\' . $letter . \'">\' . apply_filters( \'the_title\', $letter ) . \'</a></h4></li>\';
}
$index_row .=\'</ul>\';
} //Index Row End
foreach( $groups as $letter => $cats )
{
$list .= \'<div class="asset-cata clearfix">\' . "\\n";
$list .= \'<div class="letter">\' . "\\n";
$list .= \'<h1>\' . apply_filters( \'the_title\', $letter ) . \'</h1>\' . "\\n"; // The Letters On Their Own
$list .= \'</div>\' . "\\n";
$list .= \'<div class="list-items">\' . "\\n";
$list .= \'<ul>\' . "\\n";
foreach( $cats as $cat )
{
$url = attribute_escape( get_category_link( $cat->term_id ) );
$name = apply_filters( \'the_title\', $cat->name );
$list .= \'<li class="item">\' . "\\n";
$list .= \'<a title="\' . $name . \'" href="\' . $url . \'">\' . $name . "\\n";
$list .= \'<span class="number">\'. $cat->count .\'</span> \' . "\\n";
$list .= \'</a>\' . "\\n";
$list .= \'</li>\' . "\\n";
}
$list .= \'</ul>\';
$list .= \'</div>\';
$list .= \'</div>\';
}
} // GRoups End
} else
$list .= \'<p>Sorry, but no cats were found</p>\';
`
这在一定程度上实现了我的愿望,但并没有把孩子的类别与他们的父母放在一起,这正是我想要实现的