我试图在一个支持PHP的文本小部件中显示一个类别列表。在子类别页面上,我需要获取当前类别父类别的id,然后使用该id返回除当前类别之外的所有该类别子类别的列表。
我尝试了以下代码,但不起作用:
<?php if (is_category( )) {
$thiscat = get_category( get_query_var( \'cat\' ) );
$catid = $thiscat->cat_ID;
$parent = $catid->category_parent;
$catlist = get_categories(
array(
\'child_of\' => $parent,
\'orderby\' => \'id\',
\'order\' => \'DESC\',
\'exclude\' => $catid,
\'hide_empty\' => \'0\'
) );
} ?>
这将显示父类别和子类别。