好吧,我想使用custom post 来完成,就像这样(它会为您提供自定义帖子的 WordPress 标准添加/编辑/删除选项,并节省大量工作)
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'university_apps',
array(
'labels' => array(
'name' => __( 'Applications' ),
'singular_name' => __( 'Application' )
),
'public' => true,
'has_archive' => true,
)
);
}
但是,自定义帖子只有WordPress 标准字段,例如Title、Content 等,这不足以实现您提到的目标,但您可以使用custom fields 来实现此目的,这意味着,您可以添加更多(自定义)字段来保存您的应用程序的url、description、icon 等,这样做,您可以使用add_meta_box,就像(也检查this tutorial)
function add_custom_meta_box() {
add_meta_box(
'custom_meta_box', // id
'Custom Meta Box', // title
'show_custom_meta_box', // callback
'university_apps', // post type
'normal', // context
'high' // priority
);
}
add_action('add_meta_boxes', 'add_custom_meta_box');
此外,您可以查看一篇不错的文章Adding Custom Fields to a Custom Post Type, the Right Way,以使用您的自定义帖子类型轻松添加自定义字段。这是 WordPress 执行您尝试执行的任务的方式。这样,您可以使用 WordPress 的核心功能,如 WP_query 等在前端查询您的自定义帖子类型,或者您可以为自定义帖子类型创建自定义模板,这样您还可以管理所有项目(自定义很容易在后面发布申请)。