为自定义文章类型向管理页添加列
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为自定义文章类型向管理页添加列相关的知识,希望对你有一定的参考价值。
// Change the columns for the edit CPT screen function change_columns( $cols ) { 'cb' => '<input type="checkbox" />', 'url' => __( 'URL', 'trans' ), 'referrer' => __( 'Referrer', 'trans' ), 'host' => __( 'Host', 'trans' ), ); return $cols; } add_filter( "manage_<CPT>_posts_columns", "change_columns" ); function custom_columns( $column, $post_id ) { switch ( $column ) { case "url": $url = get_post_meta( $post_id, 'url', true); echo '<a href="' . $url . '">' . $url. '</a>'; break; case "referrer": $refer = get_post_meta( $post_id, 'referrer', true); echo '<a href="' . $refer . '">' . $refer. '</a>'; break; case "host": echo get_post_meta( $post_id, 'host', true); break; } } add_action( "manage_posts_custom_column", "custom_columns", 10, 2 ); // Make these columns sortable function sortable_columns() { 'url' => 'url', 'referrer' => 'referrer', 'host' => 'host' ); } add_filter( "manage_edit-<CPT>_sortable_columns", "sortable_columns" ); // Filter the request to just give posts for the given taxonomy, if applicable. function taxonomy_filter_restrict_manage_posts() { global $typenow; // If you only want this to work for your specific post type, // check for that $type here and then return. // This function, if unmodified, will add the dropdown for each // post type / taxonomy combination. $filters = get_object_taxonomies( $typenow ); foreach ( $filters as $tax_slug ) { $tax_obj = get_taxonomy( $tax_slug ); 'show_option_all' => __('Show All '.$tax_obj->label ), 'taxonomy' => $tax_slug, 'name' => $tax_obj->name, 'orderby' => 'name', 'selected' => $_GET[$tax_slug], 'hierarchical' => $tax_obj->hierarchical, 'show_count' => false, 'hide_empty' => true ) ); } } } add_action( 'restrict_manage_posts', 'taxonomy_filter_restrict_manage_posts' );
以上是关于为自定义文章类型向管理页添加列的主要内容,如果未能解决你的问题,请参考以下文章
jquery datatable后台分页移动端隐藏列自定义列显示格式
在 Wordpress 中,如何将自定义帖子类型的默认管理员排序顺序设置为自定义列?