我有点像wordpress的noob,我正在一头扎进一个课程创建插件。结构将被拆除program > course > level > lesson. 现在我已经将课程设置为自定义的职位类型和级别,课程和计划是分类法。基本上,我可以使用帮助创建一个导航路径,在该路径中,您首先选择一个程序,然后选择一个课程,然后选择一个级别,然后选择一个课程。我绞尽脑汁,有点困了。就像我说的,我对Wordpress和php还很陌生。。。
通过使用自定义的帖子类型和分类法,这是一种可行的方法吗?有人有什么建议或资源吗?我不确定是应该为此创建一个自定义主题模板文件,还是只在页面中使用一个短代码进行导航。
Program
|
/ \\
/ \\
Course1 Course2
/\\ /\\
/ \\ / \\
Lv1 Lv2 Lv1 Lv2
/\\ /\\ /\\ /\\
Lessons Lessons Lessons
下面是我到目前为止的情况(抱歉,时间太长了)。它工作得很好,我只是还没有完全弄清楚如何组织它。下面我刚刚设置了自定义帖子类型和分类法。就是这样
<?php
/**
* Plugin Name: Course Manager
* Description: Creates Programs, Courses, Levels and Lessons
* Version: The Plugin\'s Version Number, e.g.: 0.1
*/
?>
<?php
function cm_lesson_cp(){
$labels = array(
\'name\' => _x( \'Lesson\', \'post type general name\' ),
\'singular_name\' => _x( \'Lesson\', \'post type singular name\' ),
\'add_new\' => _x( \'Add New\', \'Lesson\' ),
\'add_new_item\' => __( \'Add New Lesson\' ),
\'edit_item\' => __( \'Edit Lesson\' ),
\'new_item\' => __( \'New Lesson\' ),
\'all_items\' => __( \'All Lessons\' ),
\'view_item\' => __( \'View Lesson\' ),
\'search_items\' => __( \'Search Lessons\' ),
\'not_found\' => __( \'No Lessons found\' ),
\'not_found_in_trash\' => __( \'No lessons found in the Trash\' ),
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Lessons\'
);
$args = array(
\'labels\' => $labels,
\'description\' => \'Enter a lesson description here.\',
\'public\' => true,
\'menu_position\' => 4,
\'supports\' => array( \'title\', \'editor\', \'excerpt\'),
\'has_archive\' => true,
);
register_post_type( \'lesson\', $args );
flush_rewrite_rules( false );
}
add_action( \'init\', \'cm_lesson_cp\' );
//Custom messages for custom post type`
function lesson_messages_cp( $messages ) {
global $post, $post_ID;
$messages[\'lesson\'] = array(
0 => \'\',
1 => sprintf( __(\'Lesson updated. <a href="%s">View Lesson</a>\'), esc_url( get_permalink($post_ID) ) ),
2 => __(\'Custom field updated.\'),
3 => __(\'Custom field deleted.\'),
4 => __(\'Lesson updated.\'),
5 => isset($_GET[\'revision\']) ? sprintf( __(\'Lesson restored to revision from %s\'), wp_post_revision_title( (int) $_GET[\'revision\'], false ) ) : false,
6 => sprintf( __(\'Lesson published. <a href="%s">View Lesson</a>\'), esc_url( get_permalink($post_ID) ) ),
7 => __(\'Lesson saved.\'),
8 => sprintf( __(\'Lesson submitted. <a target="_blank" href="%s">Preview Lesson</a>\'), esc_url( add_query_arg( \'preview\', \'true\', get_permalink($post_ID) ) ) ),
9 => sprintf( __(\'Lesson scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Lesson</a>\'), date_i18n( __( \'M j, Y @ G:i\' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
10 => sprintf( __(\'Lesson draft updated. <a target="_blank" href="%s">Preview Lesson</a>\'), esc_url( add_query_arg( \'preview\', \'true\', get_permalink($post_ID) ) ) ),
);
return $messages;
}
add_filter( \'post_updated_messages\', \'lesson_messages_cp\' );
// Register Program Taxonomy
function program_taxonomy_cp() {
$args = array();
register_taxonomy( \'program\', \'lesson\', $args );
}
add_action( \'init\', \'program_taxonomy_cp\', 0 );
// Customize taxonomy
function program_taxonomy_setting_cp() {
$labels = array(
\'name\' => _x( \'Program\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Program\', \'taxonomy name\' ),
\'search_items\' => __( \'Search Programs\' ),
\'all_items\' => __( \'All Programs\' ),
\'parent_item\' => __( \'Parent Program Category\' ),
\'parent_item_colon\' => __( \'Parent Program Category:\' ),
\'edit_item\' => __( \'Edit Program Category\' ),
\'update_item\' => __( \'Update Program\' ),
\'add_new_item\' => __( \'Add New Program\' ),
\'new_item_name\' => __( \'New Program\' ),
\'menu_name\' => __( \'Programs\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
);
register_taxonomy( \'program\', \'lesson\', $args );
}
add_action( \'init\', \'program_taxonomy_setting_cp\', 0 );
// Register Course Taxonomy
function course_taxonomy_cp() {
$args = array();
register_taxonomy( \'course\', \'lesson\', $args );
}
add_action( \'init\', \'course_taxonomy_cp\', 0 );
// Customize taxonomy
function course_taxonomy_setting_cp() {
$labels = array(
\'name\' => _x( \'Course\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Course\', \'taxonomy name\' ),
\'search_items\' => __( \'Search Courses\' ),
\'all_items\' => __( \'All Courses\' ),
\'parent_item\' => __( \'Parent Course Category\' ),
\'parent_item_colon\' => __( \'Parent Course Category:\' ),
\'edit_item\' => __( \'Edit Course Category\' ),
\'update_item\' => __( \'Update Course\' ),
\'add_new_item\' => __( \'Add New Course\' ),
\'new_item_name\' => __( \'New Course\' ),
\'menu_name\' => __( \'Courses\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
);
register_taxonomy( \'course\', \'lesson\', $args );
}
add_action( \'init\', \'course_taxonomy_setting_cp\', 0 );
// Register Custom Taxonomy "Level"
function level_taxonomy_cp() {
$args = array();
register_taxonomy( \'glossary\', \'term\', $args );
}
add_action( \'init\', \'level_taxonomy_cp\', 0 );
// Customize taxonomy
function level_taxonomy_setting_cp() {
$labels = array(
\'name\' => _x( \'Levels\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Level\', \'taxonomy name\' ),
\'search_items\' => __( \'Search Levels\' ),
\'all_items\' => __( \'All Levels\' ),
\'parent_item\' => __( \'Parent Level Category\' ),
\'parent_item_colon\' => __( \'Parent Level Category:\' ),
\'edit_item\' => __( \'Edit Level Category\' ),
\'update_item\' => __( \'Update Level\' ),
\'add_new_item\' => __( \'Add New Level\' ),
\'new_item_name\' => __( \'New Level\' ),
\'menu_name\' => __( \'Levels\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
);
register_taxonomy( \'level\', \'lesson\', $args );
}
add_action( \'init\', \'level_taxonomy_setting_cp\', 0 );