// Add this code to your theme's functions.php file or a custom plugin
function create_collaborator_post_type() {
$args = array(
'public' => true,
'label' => 'Collaborators',
'supports' => array('title', 'editor', 'thumbnail'),
// Add any additional fields you need for collaborators
// such as 'region', 'profession', etc.
);
register_post_type('collaborator', $args);
}
add_action('init', 'create_collaborator_post_type');
<!-- Add this code to page-region.php -->
<form method="post">
<label for="name">Name:</label>
<input type="text" name="name" id="name" required>
<!-- Add more fields for region-specific information -->
<input type="submit" value="Submit">
</form>
<!-- Add this code to page-profession.php -->
<form method="post">
<label for="name">Name:</label>
<input type="text" name="name" id="name" required>
<!-- Add more fields for profession-specific information -->
<input type="submit" value="Submit">
</form>
流程表提交:处理每个模板文件中的表单提交并为协作者创建新帖子:
// Add this code to page-region.php and page-profession.php after the form HTML
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$name = $_POST['name'];
// Get other form fields
$post_data = array(
'post_title' => $name,
'post_type' => 'collaborator',
// Set other post meta values based on form input
);
$post_id = wp_insert_post($post_data);
if ($post_id) {
// Display a success message or redirect to a thank-you page
} else {
// Display an error message
}
}
显示个人卡片:查询并显示每个模板文件中的个人卡片:
// Add this code to page-region.php and page-profession.php after the form processing code
$args = array(
'post_type' => 'collaborator',
// Add additional arguments to filter by region or profession
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
// Display the collaborator information
the_title('<h2>', '</h2>');
the_content();
// Display additional fields
// Add appropriate HTML and styling for the personal cards
}
wp_reset_postdata();
} else {
// Display a message when no collaborators are found
}
1条答案
按热度按时间pjngdqdw1#
创建自定义帖子类型:
创建页面模板:为每个地区和职业创建单独的模板文件。例如,在主题文件夹中创建page-region.php和page-professional.php。
将表单添加到每个模板:在每个模板文件中,添加一个表单以收集协作者信息:
流程表提交:处理每个模板文件中的表单提交并为协作者创建新帖子:
显示个人卡片:查询并显示每个模板文件中的个人卡片:
请记住根据您的特定需求定制代码,例如添加其他字段、样式化和定制循环以根据需要显示协作者详细信息。
请注意,此代码作为起点,可能需要根据您的特定需求和主题结构进行进一步调整。