图片待添加
图片待添加

WordPress后台列表显示分类ID,标签ID,文章ID,页面ID,用户ID号

2020-03-16 15:18 分类:WordPress主题开发制作教程 阅读(次阅读) 标签:,

我们在WordPress主题开发的时候经常需要获取WordPress分类ID号,之前我介绍过一个方法:

如何查看获取WordPress分类目录与标签和文章的ID

很多朋友觉得这样不方便,就介绍另外一种方法,直接在WordPress后台列表显示WordPress分类ID号,标签ID,文章ID,页面ID,用户ID号.

下面说说如何改造WordPress后台直接显示WordPress分类ID

可以将下面的代码添加到当前主题 functions.php 文件中:

// WordPress后台列表直接显示分类ID,标签ID,文章ID,页面ID,用户ID号
//
function ssid_column($cols) {
    $cols['ssid'] = 'ID';
    return $cols;
}
// Echo the ID for the new column
function ssid_value($column_name, $id) {
    if ($column_name == 'ssid')
        echo $id;
}
function ssid_return_value($value, $column_name, $id) {
    if ($column_name == 'ssid')
        $value = $id;
    return $value;
}
// Output CSS for width of new column
function ssid_css() {
?>
<style type="text/css">
    #ssid { width: 50px; } /* Simply Show IDs */
</style>
<?php
}
// Actions/Filters for various tables and the css output
function ssid_add() {
    add_action('admin_head', 'ssid_css');
    add_filter('manage_posts_columns', 'ssid_column');
    add_action('manage_posts_custom_column', 'ssid_value', 10, 2);
    add_filter('manage_pages_columns', 'ssid_column');
    add_action('manage_pages_custom_column', 'ssid_value', 10, 2);
    add_filter('manage_media_columns', 'ssid_column');
    add_action('manage_media_custom_column', 'ssid_value', 10, 2);
    add_filter('manage_link-manager_columns', 'ssid_column');
    add_action('manage_link_custom_column', 'ssid_value', 10, 2);
    add_action('manage_edit-link-categories_columns', 'ssid_column');
    add_filter('manage_link_categories_custom_column', 'ssid_return_value', 10, 3);
    foreach ( get_taxonomies() as $taxonomy ) {
        add_action("manage_edit-${taxonomy}_columns", 'ssid_column');
        add_filter("manage_${taxonomy}_custom_column", 'ssid_return_value', 10, 3);
    }
    add_action('manage_users_columns', 'ssid_column');
    add_filter('manage_users_custom_column', 'ssid_return_value', 10, 3);
    add_action('manage_edit-comments_columns', 'ssid_column');
    add_action('manage_comments_custom_column', 'ssid_value', 10, 2);
}
add_action('admin_init', 'ssid_add');

代码来自插件:Simply Show IDs

当然你也可以直接安装该插件。


本文地址: https://www.wpyi.com/houtai-xianshi-id.html