您需要执行以下操作:
--首先,如果尚未创建子主题,请创建子主题。如果你的主题需要更新,这将避免你失去所有的努力。有关如何执行此操作的更多信息,请参见:https://codex.wordpress.org/Child_Themes
--然后,转到您的函数。php并创建自定义帖子类型。它可以是这样的:
//custom post type
/*
* Creating a function to create our CPT
*/
function my_custom_post_type() {
// Set UI labels for Custom Post Type
$labels = array(
\'name\' => _x( \'Properties\', \'Post Type General Name\', \'custompsotype\' ),
\'singular_name\' => _x( \'Property\', \'Post Type Singular Name\', \'custompsotype\' ),
\'menu_name\' => __( \'Properties\', \'custompsotype\' ),
\'parent_item_colon\' => __( \'Parent Property\', \'custompsotype\' ),
\'all_items\' => __( \'All Properties\', \'custompsotype\' ),
\'view_item\' => __( \'View Property\', \'custompsotype\' ),
\'add_new_item\' => __( \'Add New Property\', \'custompsotype\' ),
\'add_new\' => __( \'Add New\', \'custompsotype\' ),
\'edit_item\' => __( \'Edit Property\', \'custompsotype\' ),
\'update_item\' => __( \'Update Property\', \'custompsotype\' ),
\'search_items\' => __( \'Search Property\', \'custompsotype\' ),
\'not_found\' => __( \'Not Found\', \'custompsotype\' ),
\'not_found_in_trash\' => __( \'Not found in Trash\', \'custompsotype\' ),
);
// Set other options for Custom Post Type
$args = array(
\'label\' => __( \'properties\', \'custompsotype\' ),
\'description\' => __( \'Properties\', \'custompsotype\' ),
\'labels\' => $labels,
// Features this CPT supports in Post Editor
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'comments\', \'revisions\', \'custom-fields\', ),
// You can associate this CPT with a taxonomy or custom taxonomy.
\'taxonomies\' => array( \'genres\' ),
/* A hierarchical CPT is like Pages and can have
* Parent and child items. A non-hierarchical CPT
* is like Posts.
*/
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 5,
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'menu_icon\' => \'dashicons-format-aside\',
\'capability_type\' => \'page\',
);
// Registering your Custom Post Type
register_post_type( \'properties\', $args );
}
/* Hook into the \'init\' action so that the function
* Containing our post type registration is not
* unnecessarily executed.
*/
add_action( \'init\', \'my_custom_post_type\', 0 );
--以下内容将创建新的职位类型。现在,您可以向其添加属性,以及属性类别(例如,“海上属性”),与您为普通帖子添加属性的方式完全相同
--您可以通过创建新的php文件来修改新帖子类型的外观/代码/布局,其中一个文件用于属性列表,名为
archive-properties.php
一个用于单个属性,名为
single-properties.php
. 您可以在此处找到更多信息:
https://codex.wordpress.org/Post_Type_Templates .
--为了向属性中添加自定义字段,我建议使用高级自定义字段(
https://www.advancedcustomfields.com/), 在我看来,它是初学者最简单的选择,有很多选择和很棒的文档。