Last active
December 12, 2022 23:42
-
-
Save renakdup/866c5410ad1b20e3190feea19ca556e4 to your computer and use it in GitHub Desktop.
WordPress entities
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Register Custom Post Type | |
function product_post_type() { | |
$labels = array( | |
'name' => _x( 'Каталог мебели', 'Post Type General Name', 'text_domain' ), | |
'singular_name' => _x( 'Товар', 'Post Type Singular Name', 'text_domain' ), | |
'menu_name' => __( 'Товары', 'text_domain' ), | |
'parent_item_colon' => __( '!!!', 'text_domain' ), | |
'all_items' => __( 'Все товары', 'text_domain' ), | |
'view_item' => __( 'Смотреть товар', 'text_domain' ), | |
'add_new_item' => __( 'Добавить новый товар', 'text_domain' ), | |
'add_new' => __( 'Добавить товар', 'text_domain' ), | |
'edit_item' => __( 'Редактировать товар', 'text_domain' ), | |
'update_item' => __( 'Обновить товар', 'text_domain' ), | |
'search_items' => __( 'Искать товар', 'text_domain' ), | |
'not_found' => __( 'Не найдено', 'text_domain' ), | |
'not_found_in_trash' => __( 'Не найдено в корзине', 'text_domain' ), | |
); | |
$args = array( | |
'label' => __( 'rs_product', 'text_domain' ), | |
'description' => __( 'Home Guide Description', 'text_domain' ), | |
'labels' => $labels, | |
'supports' => array( 'title', 'thumbnail', 'editor' ), | |
'hierarchical' => false, | |
'public' => true, | |
'show_ui' => true, | |
'show_in_menu' => true, | |
'show_in_nav_menus' => true, | |
'show_in_admin_bar' => true, | |
'menu_position' => 5, | |
'menu_icon' => '', | |
'can_export' => true, | |
'has_archive' => true, | |
'exclude_from_search' => false, | |
'publicly_queryable' => true, | |
'capability_type' => 'page', | |
'rewrite' => array( | |
'slug' => 'catalogue', | |
// 'slug' => 'products', | |
'with_front' => true, | |
'pages' => true, | |
'feeds' => true, | |
), | |
//"cptp_permalink_structure" => "/blog/%category%/%postname%/" | |
); | |
register_post_type( 'rs_product', $args ); | |
} | |
add_action( 'init', 'product_post_type', 0 ); | |
function rs_product_rewrite_rules( $rules ) { | |
$newRules = array(); | |
$newRules[ 'catalogue/(.+)/(.+)/page/([0-9]{1,})/?$' ] = 'index.php?rs_category=$matches[2]&paged=$matches[3]'; // top level category | |
$newRules[ 'catalogue/(.+)/page/([0-9]{1,})/?$' ] = 'index.php?rs_category=$matches[1]&paged=$matches[2]'; // top level category | |
$newRules[ 'catalogue/(.+)/(.+)/(.+)/?$' ] = 'index.php?rs_product=$matches[3]&category_hg=$matches[1]&podcategory_hg=$matches[2]'; // my custom structure will always have the post name as the 5th uri segment | |
$newRules[ 'catalogue/(.+)/(.+)/?$' ] = 'index.php?rs_category=$matches[2]'; // sub category | |
$newRules[ 'catalogue/(.+)/?$' ] = 'index.php?rs_category=$matches[1]'; // top level category | |
return array_merge( $newRules, $rules ); | |
} | |
add_filter( 'rewrite_rules_array', 'rs_product_rewrite_rules' ); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Register Custom Taxonomy | |
function product_category_taxonomy() { | |
$labels = array( | |
'name' => 'Категории', | |
'singular_name' => 'Категория', | |
'menu_name' => 'Категории', | |
'all_items' => 'Все категории', | |
'parent_item' => 'Родительская категория', | |
'parent_item_colon' => 'Родительская:', | |
'new_item_name' => 'Новая категория', | |
'add_new_item' => 'Добавить новую категорию', | |
'edit_item' => 'Редактировать категорию', | |
'update_item' => 'Обновить категорию', | |
'separate_items_with_commas' => 'Разделяйте элементы запятыми', | |
'search_items' => 'Искать элкменты', | |
'add_or_remove_items' => 'Добавить или удалить элементы', | |
'choose_from_most_used' => 'Выбрать из наиболее используемых', | |
'not_found' => 'Не найдено', | |
); | |
$rewrite = array( | |
'slug' => 'catalogue', | |
'with_front' => true, | |
'hierarchical' => true, | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
'query_var' => true, | |
'rewrite' => $rewrite, | |
); | |
register_taxonomy( 'rs_category', 'rs_product', $args ); | |
} | |
// Hook into the 'init' action | |
add_action( 'init', 'product_category_taxonomy', 0 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Register Custom Taxonomy | |
function product_tags() { | |
$labels = array( | |
'name' => 'Теги товара', | |
'singular_name' => 'Тег товара', | |
'menu_name' => 'Теги', | |
'all_items' => 'Все теги', | |
'parent_item' => '??? Родительский тег', | |
'parent_item_colon' => '??? Родительский тег:', | |
'new_item_name' => 'Новый тег', | |
'add_new_item' => 'Добавить тег', | |
'edit_item' => 'Редактировать тег', | |
'update_item' => 'Обновить тег', | |
'separate_items_with_commas' => 'Разделяйте теги запятыми', | |
'search_items' => 'Искать теги', | |
'add_or_remove_items' => 'Добавить или удалить теги', | |
'choose_from_most_used' => 'Выбрать из популярных', | |
'not_found' => 'Не найдено', | |
); | |
$rewrite = array( | |
'slug' => 'catalogue/tag', | |
'with_front' => true, | |
'hierarchical' => true, | |
); | |
$args = array( | |
'labels' => $labels, | |
'hierarchical' => true, | |
'public' => true, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'show_in_nav_menus' => true, | |
'show_tagcloud' => true, | |
'rewrite' => $rewrite, | |
); | |
register_taxonomy( 'rs_product_tags', 'rs_product', $args ); | |
} | |
// Hook into the 'init' action | |
add_action( 'init', 'product_tags', 0 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment