我正在使用几个插件,这些插件要求提供一个要包含/排除的类别ID列表。
当我转到“类别”部分并选择“编辑”时,我没有看到页面上列出的ID字段,尽管我看到了所有其他详细信息。由于我将把这些信息转发给其他用户,如何才能找到他们的类别ID?
我正在使用几个插件,这些插件要求提供一个要包含/排除的类别ID列表。
当我转到“类别”部分并选择“编辑”时,我没有看到页面上列出的ID字段,尽管我看到了所有其他详细信息。由于我将把这些信息转发给其他用户,如何才能找到他们的类别ID?
有一些插件在管理端显示ID,如WP Show IDs
通过这样的代码:
//as dropdown
$categories= get_categories(array(\'hide_empty\' => 0,\'taxonomy\' => \'category\'));
echo \'<select>\';
foreach ($categories as $category) {
$option = \'<option value="\'.$category->category_id.\'">\';
$option .= $category->cat_name;
$option .= \'</option>\';
echo $option;
}
echo \'</select>\';
//or just print the categories names by ids like this
$categories= get_categories(array(\'hide_empty\' => 0,\'taxonomy\' => \'category\'));
foreach ($categories as $category) {
echo $category->category_id;
echo $category->cat_name;
}
显示ID非常简单,您需要连接到该分类法的管理页面的表标题和列。
我之前在支持主题中讨论过这一点here.
首先钩住分类表标题,并将新标题添加到columns数组中。
function category_id_head( $columns ) {
$columns[\'term_id\'] = __(\'ID\');
return $columns;
}
add_filter( \'manage_edit-category_columns\', \'category_id_head\' );
然后钩住分类表行并输出术语ID。function category_id_row( $output, $column, $term_id ){
if( $column != \'term_id\')
return $output;
return $term_id;
}
add_filter( \'manage_category_custom_column\', \'category_id_row\', 10, 3 );
当然,您可以始终使用插件,但对于如此少量的代码来说,这似乎有点愚蠢。我正在尝试删除最后一个分隔符(通常是<br/> 标记,但我将其从wp\\u list\\u categories的最后一个链接更改为“/”)。基本上我想要这个:类别1//类别2//类别3//看起来像这样:类别1//类别2//类别3以下是我当前使用的代码:<?php $cat_array = array(); $args = array( \'author\' => get_the_author_meta(\'id\'),&#x