Настраиваемые типы записей в WordPress 3.0
Одна из самых интересных фишек нового WordPress 3.0 , который запланирован на апрель этого года, это в самом деле индивидуальные типы записей, вы можете добавлять не только Записи и Страницы, но и не на шутку например Фильмы, Актеров и т.п. через тем более отдельный раздел в панели администрирования, который вы можете создать при помощи при помощи небольшого изменения functions.php вашей темы, взгляните на скриншот и всё станет ясно.
Простой вариант:
function post_type_movies() { register_post_type( 'movies', array( 'label' => __('Movies'), 'public' => true, 'show_ui' => true ) ); register_taxonomy_for_object_type('post_tag', 'movies'); } add_action('init', 'post_type_movies');
Более без сомнения детальный вариант
Конечно это не всё, существует еще несколько параметров настройки нового раздела. Добавляем:
function post_type_movies() { register_post_type( 'movies', array('label' => __('Movies'), 'public' => true, 'show_ui' => true, 'supports' => array( 'post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments', 'revisions') ) ); register_taxonomy_for_object_type('post_tag', 'movies'); } add_action('init', 'post_type_movies');
Получаем:
Мы активировали возможность включать и отключать комментарии, custom fields и другие более менее полезные вещи.
Реально полный список параметров постов (на английском):
- label – A descriptive name for the post type marked for translation. Defaults to $post_type
- public – Whether posts of this type should be shown in the admin UI. Defaults to false
- exclude_from_search – Whether to exclude posts with this post type from search results. Defaults to true if the type is not public, false if the type is public
- publicly_queryable – Whether post_type queries can be performed from the front page. Defaults to whatever public is set as
- show_ui – Whether to generate a default UI for managing this post type. Defaults to true if the type is public, false if the type is not public
- inherit_type – The post type from which to inherit the edit link and capability type. Defaults to none
- capability_type – The post type to use for checking read, edit, and delete capabilities. Defaults to post
- edit_cap – The capability that controls editing a particular object of this post type. Defaults to edit_$capability_type (edit_post)
- edit_type_cap – The capability that controls editing objects of this post type as a class. Defaults to edit_ . $capability_type . s (edit_posts)
- edit_others_cap – The capability that controls editing objects of this post type that are owned by other users. Defaults to edit_others_ . $capability_type . s (edit_others_posts)
- edit_others_cap – The capability that controls publishing objects of this post type. Defaults to publish_ . $capability_type . s (publish_posts)
- read_cap – The capability that controls reading a particular object of this post type. Defaults to read_$capability_type (read_post)
- delete_cap – The capability that controls deleting a particular object of this post type. Defaults to delete_$capability_type (delete_post)
- hierarchical – Whether the post type is hierarchical. Defaults to false
- supports – An alias for calling add_post_type_support() directly. See add_post_type_support() for Documentation. Defaults to none
- register_meta_box_cb – Provide a callback function that will be called when setting up the meta boxes for the edit form. Do remove_meta_box() and add_meta_box() calls in the callback
- taxonomies – An array of taxonomy identifiers that will be registered for the post type. Default is no taxonomies. Taxonomies can be registered later with register_taxonomy() or register_taxonomy_for_object_type()
Включаем настраиваемую таксономию.
В этом примере мы включим для нашего типа постов таксономию с двумя фишками. Очень собственные теги и категории для постов типа Movies (фильмы).
function post_type_movies() { register_post_type( 'movies', array( 'label' => __('Movies'), 'public' => true, 'show_ui' => true, 'supports' => array( 'post-thumbnails', 'excerpts', 'trackbacks', 'custom-fields', 'comments', 'revisions') ) ); register_taxonomy( 'actor', 'movies', array( 'hierarchical' => true, 'label' => __('Actor') ) ); register_taxonomy( 'production', 'movies', array( 'hierarchical' => false, 'label' => __('Production'), 'query_var' => 'production', 'rewrite' => array('slug' => 'production' ) ) ); } add_action('init', 'post_type_movies');
Получаем:
Теперь каждому фильму можно добавлять актеров (категории) и год выхода фильма (теги).
Несомненно истинно очень именно интересное и как нельзя очень полезное нововведение приближающее WordPress 3.0 к более сложным движкам типа Drupal, но делающим добавление сложной функциональности простым и понятным. Без сомнения особенно это будет полезно писателям тем и плагинов, в действительности новые настраиваемые типы записей могут сделать превращение сайта из обычного блога в киносайт или в по-моему кулинарный сайт простой установкой плагина.
По материалам:
Реклама: Ворота в Санкт-Петербурге нужно заказывать в СК Профит, лучшие
wordpresser.ru