Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ================== В этом блоке все относится к статьям ===========*/
- /* Регистрируем тип записей для статей */
- add_action('init', 'my_custom_init2');
- function my_custom_init2() {
- $labels = array(
- 'name' => 'Статьи о снах',
- 'singular_name' => 'Статья',
- 'add_new' => 'Добавить новую',
- 'add_new_item' => 'Добавить новую статью',
- 'edit_item' => 'Редактировать статью',
- 'new_item' => 'Новая статья',
- 'view_item' => 'Посмотреть статью',
- 'search_items' => 'Найти статью',
- 'not_found' => 'Статей не найдено',
- 'not_found_in_trash' => 'В корзине статей не найдено',
- 'parent_item_colon' => '',
- 'menu_name' => 'Статьи'
- );
- $args = array(
- 'labels' => $labels,
- 'public' => true,
- 'publicly_queryable' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'query_var' => true,
- 'rewrite' => false,
- 'capability_type' => 'post',
- 'has_archive' => 'stati',
- 'hierarchical' => false,
- 'menu_position' => 5,
- 'supports' => array('title','editor','author','custom-fields','comments','thumbnail')
- );
- register_post_type('stati', $args);
- }
- /* Регистрируем таксономии для статей */
- function create_my_taxonomies() {
- register_taxonomy('metki', 'stati', array(
- 'hierarchical' => false,
- 'label' => 'Метки',
- 'query_var' => true,
- 'rewrite' => false
- ));
- register_taxonomy('rubriki', 'stati', array(
- 'hierarchical' => true,
- 'publicly_queryable' => true,
- 'label' => 'Рубрики',
- 'rewrite' => false,
- 'query_var' => true
- ));
- }
- add_action('init', 'create_my_taxonomies', 0);
- /* переписываем URL статей, архива и связанных таксономий */
- global $wp_rewrite;
- // структура статей
- $stati_structure = '/stati/%category%/%stati%/';
- $wp_rewrite->add_rewrite_tag("%stati%", '([^/]+)', "stati=");
- $wp_rewrite->add_permastruct('stati', $stati_structure, false);
- // структура комментариев для статей
- $stati_comment = '/stati/%category%/%stati%/';
- $wp_rewrite->add_rewrite_tag("%stati%", '([^/]+)', "stati=");
- $wp_rewrite->add_rewrite_tag('%cpage%', '1',"stati=$matches[1]&cpage=1");
- $wp_rewrite->add_permastruct('comment-page-1', $stati_comment, true);
- // структура архива статей
- $stati_archive_structure = '%stati_cpt%/page/%paged%/';
- $wp_rewrite->add_rewrite_tag('%stati_cpt%', 'stati', '/sonnik/?post_type=stati');
- $wp_rewrite->add_rewrite_tag('%paged%', '([^/]+)', '/sonnik/?post_type=stati&paged=$matches[1]');
- $wp_rewrite->add_permastruct('stati_archive', $stati_archive_structure, false);
- // структура рубрик для статей
- $rubriki_structure = '/stati/rubriki/%rubriki%';
- $wp_rewrite->add_rewrite_tag("%rubriki%", '([^/]+)', "rubriki=");
- $wp_rewrite->add_permastruct('rubriki', $rubriki_structure, false);
- // структура меток для статей
- $metki_structure = '/stati/metki/%metki%';
- $wp_rewrite->add_rewrite_tag("%metki%", '([^/]+)', "metki=");
- $wp_rewrite->add_permastruct('metki', $metki_structure, false);
- add_filter('post_type_link', 'stati_permalink', 10, 3);
- function stati_permalink($permalink, $post_id, $leavename) {
- $post = get_post($post_id);
- $rewritecode = array( '%category%');
- if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {
- $unixtime = strtotime($post->post_date);
- $category = '';
- if ( strpos($permalink, '%category%') !== false ) {
- $cats = wp_get_object_terms($post->ID, 'rubriki');
- if ( $cats ) {
- usort($cats, '_usort_terms_by_ID'); // order by ID
- $category = $cats[0]->slug;
- }
- }
- $rewritereplace = array($category);
- $permalink = str_replace($rewritecode, $rewritereplace, $permalink);
- }
- return $permalink;
- }
- $wp_rewrite->flush_rules();
- // Переписываем стандартный цикл Wordpresss при необходимых условиях
- function hwl_home_pagesize( $query ) {
- if ( is_post_type_archive( 'stati' ) and !is_tax('rubriki') and !is_tax('metki') and !is_admin()) {
- // Display 50 posts for a custom post type called 'movie'
- $query->set( 'posts_per_page', 5 );
- return;
- }
- if ( is_tax('rubriki')) {
- // Display 50 posts for a custom post type called 'movie'
- $query->set( 'posts_per_page', -1 );
- return;
- }
- if ( is_tax('metki')) {
- // Display 50 posts for a custom post type called 'movie'
- $query->set( 'posts_per_page', 10 );
- return;
- }
- }
- add_action( 'pre_get_posts', 'hwl_home_pagesize', 1 );
- add_action( 'load-post.php', 'thumb_meta' );
- add_action( 'load-post-new.php', 'thumb_meta' );
Advertisement
Add Comment
Please, Sign In to add comment