wordpress后台无插件显示文章和分类ID

我们只需要在主题的functions.php文件最后加上如下代码就OK了。

  1. /**
  2.  * 为WordPress后台的文章、分类等显示ID From wpdaxue.com
  3.  */
  4. // 添加一个新的列 ID
  5. function ssid_column($cols) {
  6. 	$cols['ssid'] = 'ID';
  7. 	return $cols;
  8. }
  9.  
  10. // 显示 ID
  11. function ssid_value($column_name, $id) {
  12. 	if ($column_name == 'ssid')
  13. 		echo $id;
  14. }
  15.  
  16. function ssid_return_value($value, $column_name, $id) {
  17. 	if ($column_name == 'ssid')
  18. 		$value = $id;
  19. 	return $value;
  20. }
  21.  
  22. // 为 ID 这列添加css 
  23. function ssid_css() {
  24. ?>
  25. <style type="text/css">
  26. 	#ssid { width: 50px; } /* Simply Show IDs */
  27. </style>
  28. <?php	
  29. }
  30.  
  31. // 通过动作/过滤器输出各种表格和CSS
  32. function ssid_add() {
  33. 	add_action('admin_head', 'ssid_css');
  34.  
  35. 	add_filter('manage_posts_columns', 'ssid_column');
  36. 	add_action('manage_posts_custom_column', 'ssid_value', 10, 2);
  37.  
  38. 	add_filter('manage_pages_columns', 'ssid_column');
  39. 	add_action('manage_pages_custom_column', 'ssid_value', 10, 2);
  40.  
  41. 	add_filter('manage_media_columns', 'ssid_column');
  42. 	add_action('manage_media_custom_column', 'ssid_value', 10, 2);
  43.  
  44. 	add_filter('manage_link-manager_columns', 'ssid_column');
  45. 	add_action('manage_link_custom_column', 'ssid_value', 10, 2);
  46.  
  47. 	add_action('manage_edit-link-categories_columns', 'ssid_column');
  48. 	add_filter('manage_link_categories_custom_column', 'ssid_return_value', 10, 3);
  49.  
  50. 	foreach ( get_taxonomies() as $taxonomy ) {
  51. 		add_action("manage_edit-${taxonomy}_columns", 'ssid_column');			
  52. 		add_filter("manage_${taxonomy}_custom_column", 'ssid_return_value', 10, 3);
  53. 	}
  54.  
  55. 	add_action('manage_users_columns', 'ssid_column');
  56. 	add_filter('manage_users_custom_column', 'ssid_return_value', 10, 3);
  57.  
  58. 	add_action('manage_edit-comments_columns', 'ssid_column');
  59. 	add_action('manage_comments_custom_column', 'ssid_value', 10, 2);
  60. }
  61.  
  62. add_action('admin_init', 'ssid_add');

发布日期:

所属分类: Wordpress, Wordpress 综合 标签:   


没有相关文章!