我为WordPress创建一个主题, 我已经尝试this tutorial创建WordPress自定义帖子,并做了一些研究但很难找到一个明确的答案(在自定义帖子上)
我正在尝试这样的事情:
+----------------------------+
|Post-type: Books |
+----------------------------+
|Name: Les misérables |
|Author: Victor Hugo |
|Genre: Poesy |
|Year-of-Pub: 1862 |
+----------------------------+
如何创建允许我添加,删除和编辑图书以及与之相关的所有详细信息的自定义帖子。并将其显示为任何帖子。
答案 0 :(得分:1)
这里是创建一个空帖子类型的代码,在你的情况下,它将是" book"
<?php
function dwwp_register_post_type() {
$args = array('public'=> true, 'label'=> 'Staff');
register_post_type( 'staff', $args);
}
add_action( 'init', 'dwwp_register_post_type' );
如果您想为自定义帖子类型指定更多信息:
<?php
//Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
function dwwp_register_post_type() {
$singular = 'Job';
$plural = 'Jobs';
$slug = str_replace( ' ', '_', strtolower( $singular ) );
$labels = array(
'name' => $plural,
'singular_name' => $singular,
'add_new' => 'Add New',
'add_new_item' => 'Add New ' . $singular,
'edit' => 'Edit',
'edit_item' => 'Edit ' . $singular,
'new_item' => 'New ' . $singular,
'view' => 'View ' . $singular,
'view_item' => 'View ' . $singular,
'search_term' => 'Search ' . $plural,
'parent' => 'Parent ' . $singular,
'not_found' => 'No ' . $plural .' found',
'not_found_in_trash' => 'No ' . $plural .' in Trash'
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => 10,
'menu_icon' => 'dashicons-businessman',
'can_export' => true,
'delete_with_user' => false,
'hierarchical' => false,
'has_archive' => true,
'query_var' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
// 'capabilities' => array(),
'rewrite' => array(
'slug' => $slug,
'with_front' => true,
'pages' => true,
'feeds' => true,
),
'supports' => array(
'title',
'editor',
'author',
'custom-fields'
)
);
register_post_type( $slug, $args );
}
add_action( 'init', 'dwwp_register_post_type' );
如果您挣扎......另请查看本教程...... http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress
祝你好运。