900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > wordpress 后台显示自定义文章的自定义字段的方法

wordpress 后台显示自定义文章的自定义字段的方法

时间:2020-05-25 14:08:47

相关推荐

wordpress 后台显示自定义文章的自定义字段的方法

wordpress官网是这样描述的:

do_action( "manage_{$post->post_type}_posts_custom_column", string $column_name, int $post_id )

wordpress官网例子:

add_filter( manage_book_posts_columns, set_custom_edit_book_columns );add_action( manage_book_posts_custom_column , custom_book_column, 10, 2 ); function set_custom_edit_book_columns($columns) { unset( $columns[author] ); $columns[ook_author] = __( Author, your_text_domain ); $columns[publisher] = __( Publisher, your_text_domain );return $columns;} function custom_book_column( $column, $post_id ) { switch ( $column ) { case ook_author : $terms = get_the_term_list( $post_id , ook_author , \ , , , \ ); if ( is_string( $terms ) )echo $terms; else_e( Unable to get author(s), your_text_domain ); break; case publisher : echo get_post_meta( $post_id , publisher , true ); break; }}

我写的,列出了文章ID,也可以显示自定义字段:

//添加面板manage_chengyuan_posts_custom_columnadd_filter( manage_chengyuan_posts_columns, set_custom_edit_book_columns );//添加表头function set_custom_edit_book_columns($columns) { unset( $columns[author] ); $columns[post_id] = __( ID, 用户ID ); return $columns;}add_action( manage_chengyuan_posts_custom_column , custom_book_column, 10, 2 );//显示每行内容function custom_book_column( $column, $post_id ) { switch ( $column ) { case post_id :echo $post_id; break; }}//添加面板

我的截图:

本文地址:/blog/648.html

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。