像这样的东西有用吗?我有遗漏什么吗?
function page_attributes_for_posts() {
register_post_type('job-bank-posts',
$args = array(
'hierarchical' => true,
'supports' => 'page-attributes'
);
);
};
add_action ('init', 'page_attributes_for_posts');这是我使用的资源之一:https://developer.wordpress.org/reference/functions/register_post_type/
发布于 2022-08-25 12:59:07
也许一个完整的例子可能会有帮助:
function create_job_bank_posts() {
register_post_type( 'book',
array(
'labels' => array(
'name' => __( 'Job Bank Posts' ),
'singular_name' => __( 'Job Bank Post' ),
'add_new' => _x('Add Job Bank Post', 'Job Bank Post'),
'add_new_item' => __('Add Job Bank Post'),
'edit_item' => __('Edit Job Bank Post'),
'new_item' => __('New Job Bank Post'),
'view_item' => __('View Job Bank Post'),
'search_items' => __('Search Job Bank Post'),
'not_found_in_trash' => __('Not found in trash'),
),
'public' => true,
'menu_icon' => 'your-dashicon',
'rewrite' => array( 'slug' => 'job_bank_posts', 'with_front' => true ),
'menu_position' => 3,
'hierarchical' => true,
'supports' => array(
'title',
'page-attributes',
'thumbnail',
'editor',
'excerpt',
'author',
'comments',
'custom-fields',
),
)
);
}
add_action( 'init', 'create_job_bank_posts' );发布于 2022-08-25 12:45:16
也许这会有帮助,他们添加了post https://make.wordpress.org/core/2021/02/10/introducing-new-post-parent-related-functions-in-wordpress-5-7/的父特性
这个插件的工作原理非常完美,可以使文章成为父https://wordpress.org/plugins/add-hierarchy-parent-to-post/
发布于 2022-08-25 17:46:53
如果这不是你想要的,请原谅我。好的,我完全利用WordPress内置的Permalink设置实现了类似的目标。这种快速方法的另一个问题是,您将不再使用类别。但它对我们很管用。
wp-admin/options-permalink.php
您将需要一个类似于以下结构的结构: /about/%category%/%postname%/
然后,我在模板中创建了一个名为“-
`<?php if (!defined('ABSPATH')) exit;
/*
Template Name: Periodic category
*/
get_header();
echo $app->templates()->get('pages/category')->render([
'post' => $post,
'parts' => [
'breadcrumbs' => $app->templates()->get('layout/breadcrumbs')->render(),
'left_menu' => $app->templates()->get('layout/menu-left')->render(['tax' => 'periodic', 'post' => $post])
]
]);
get_footer();
`
然后要为每个类别创建一个页面,并在post编辑器.中选择周期分类. the作为模板。
上面的答案为您提供了为帖子添加多个家长页面的机会。如果您只是想要一个父页面,则如下所示:
从仪表板中选择
如果这里允许的话,我很乐意分享文件等等。请原谅我是新来的。很高兴向别人学习。
https://stackoverflow.com/questions/73487640
复制相似问题