如何解决添加新帖子类型时使其参数动态化
我说的都是假设和疑惑,
以下是注册名为“post_type
”的 book
所需的编码。
/**
* Register a custom post type called "book".
*
* @see get_post_type_labels() for label keys.
*/
function wpdocs_codex_book_init() {
$labels = array(
'name' => _x( 'Books','Post type general name','textdomain' ),'singular_name' => _x( 'Book','Post type singular name','menu_name' => _x( 'Books','Admin Menu text','name_admin_bar' => _x( 'Book','Add New on Toolbar','add_new' => __( 'Add New','add_new_item' => __( 'Add New Book','new_item' => __( 'New Book','edit_item' => __( 'Edit Book','view_item' => __( 'View Book','all_items' => __( 'All Books','search_items' => __( 'Search Books','parent_item_colon' => __( 'Parent Books:','not_found' => __( 'No books found.','not_found_in_trash' => __( 'No books found in Trash.','featured_image' => _x( 'Book Cover Image','Overrides the “Featured Image” phrase for this post type. Added in 4.3','set_featured_image' => _x( 'Set cover image','Overrides the “Set featured image” phrase for this post type. Added in 4.3','remove_featured_image' => _x( 'Remove cover image','Overrides the “Remove featured image” phrase for this post type. Added in 4.3','use_featured_image' => _x( 'Use as cover image','Overrides the “Use as featured image” phrase for this post type. Added in 4.3','archives' => _x( 'Book archives','The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4','insert_into_item' => _x( 'Insert into book','Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post). Added in 4.4','uploaded_to_this_item' => _x( 'Uploaded to this book','Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post). Added in 4.4','filter_items_list' => _x( 'Filter books list','Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”. Added in 4.4','items_list_navigation' => _x( 'Books list navigation','Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”. Added in 4.4','items_list' => _x( 'Books list','Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”. Added in 4.4',);
$args = array(
'labels' => $labels,'public' => true,'publicly_queryable' => true,'show_ui' => true,'show_in_menu' => true,'query_var' => true,'rewrite' => array( 'slug' => 'book' ),'capability_type' => 'post','has_archive' => true,'hierarchical' => false,'menu_position' => null,'supports' => array( 'title','editor','author','thumbnail','excerpt','comments' ),);
register_post_type( 'book',$args );
}
add_action( 'init','wpdocs_codex_book_init' );
使用 get_option('book_slug','book')
之类的命令,我想根据来自 options
的信息使此帖子类型的 slug 动态化。这是 singular_name
等。您可以在标签中展开它。
'rewrite' => array( 'slug' => get_option('book_slug','book') ),
当然,我知道发生此更改时 permalinks
必须为 flushed
。 (这不是问题)。但我担心的是这是否会破坏 wordpress 的典型行为?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。