WordPress後臺顯示文章、分類、頁面、標簽、評論、用戶等的 ID

WordPress後臺默認是不顯示文章、分類等的ID的,查看起來非常不方便,今天就分享一個非常全面的顯示ID的方法,支援 文章、頁面、鏈接、多媒體、評論、分類、標簽、用戶 等,也就是在這些管理頁面的列表中,會添加一列 ID,如下圖所示:

simply-show-ids-wpdaxue_com

可以直接下載安裝 Simply Show IDs 外掛就可以實現該功能(雖然2年多沒有更新,但是在WP 3.5.2 測試通過)。

你也可以直接將下面的代碼(來自該外掛)添加到當前主題的 functions.php 文件即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
 * 為WordPress後臺的文章、分類等顯示ID From wpdaxue.com
 */
// 添加一個新的列 ID
function ssid_column($cols) {
	$cols['ssid'] = 'ID';
	return $cols;
}
 
// 顯示 ID
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;
}
 
// 為 ID 這列添加css 
function ssid_css() {
?>
<style type="text/css">
	#ssid { width: 50px; } /* Simply Show IDs */
</style>
<?php	
}
 
// 通過動作/過濾器輸出各種表格和CSS
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');

/**
* 為WordPress後臺的文章、分類等顯示ID From wpdaxue.com
*/
// 添加一個新的列 ID
function ssid_column($cols) {
$cols[‘ssid’] = ‘ID’;
return $cols;
} // 顯示 ID
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;
} // 為 ID 這列添加css
function ssid_css() {
?>
<style type="text/css">
#ssid { width: 50px; } /* Simply Show IDs */
</style>
<?php
} // 通過動作/過濾器輸出各種表格和CSS
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’);

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *