wp_get_nav_menu_items() и вывести свою разметку// Получаем элементы меню по ID.
$nav_menu_items = wp_get_nav_menu_items( $menu_id );
// Или получаем элементы меню по location.
$menu_location = 'primary';
$locations = get_nav_menu_locations();
if ( isset( $locations[ $menu_location ] ) ) {
$nav_menu_items = wp_get_nav_menu_items( $locations[ $menu_location ] );
} __(), _e(), esc_html__(), esc_html_e(), _x() и _ex()_x( 'Read', 'past participle: books I have read', 'text_domain' );load_theme_textdomain()register_post_type() и register_taxonomy()get_template_part( 'templates/archive/post', get_post_type() );pre_get_postswp_get_nav_menu_items() по переданному ID или location// Получаем элементы меню по ID.
$nav_menu_items = wp_get_nav_menu_items( $menu_id );
// Получаем элементы меню по location.
$menu_location = 'primary';
$locations = get_nav_menu_locations();
if ( isset( $locations[ $menu_location ] ) ) {
$nav_menu_items = wp_get_nav_menu_items( $locations[ $menu_location ] );
}pre_get_posts. Используйте проверки is_date(), is_year(), is_month() и is_day()template_redirect с теми же проверкамиfunction get_yoast_custom_title() {
if ( is_single() ) {
$string = get_the_title();
} else {
$string = 'Заголовок по умолчанию';
}
return $string;
}
// Define the action for register yoast_variable replacments.
function register_custom_yoast_variables() {
wpseo_register_var_replacement( '%%CustomTitle%%', 'get_yoast_custom_title', 'advanced', __( 'Some instead title text', 'wpgen' ) );
}
// Add action.
add_action( 'wpseo_register_extra_replacements', 'register_custom_yoast_variables' );function get_category_post_count() {
$string = '';
if ( is_category() && isset( get_queried_object()->count ) ) {
$string = get_queried_object()->count;
}
return $string;
}
// Define the action for register yoast_variable replacments.
function register_custom_yoast_variables() {
wpseo_register_var_replacement( '%%PostCount%%', 'get_category_post_count', 'advanced', __( 'Some instead title text', 'wpgen' ) );
}
// Add action.
add_action( 'wpseo_register_extra_replacements', 'register_custom_yoast_variables' ); register_post_type() указал аргумент 'has_archive' => 'repetitors', это общий архив для всех записей этого типа. Так же вам будет достаточно регистрации одной таксономииadd_action( 'init', 'education_register_post_type' );
function education_register_post_type() {
// Taxonomy repetitor_cat.
register_taxonomy( 'repetitor_cat', array( 'repetitor' ), array(
'labels' => array(
'name' => _x( 'Repetitor category', 'taxonomy general name', 'education' ),
'singular_name' => _x( 'Repetitor categories', 'taxonomy singular name', 'education' ),
'search_items' => __( 'Search Repetitor category', 'education' ),
'popular_items' => __( 'Popular Repetitor category', 'education' ),
'all_items' => __( 'All Repetitor categories', 'education' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Repetitor category', 'education' ),
'update_item' => __( 'Update Repetitor category', 'education' ),
'add_new_item' => __( 'Add new Repetitor category', 'education' ),
'new_item_name' => __( 'New Repetitor category name', 'education' ),
'menu_name' => __( 'Repetitor categories', 'education' ),
),
'public' => true,
'show_tagcloud' => true,
'hierarchical' => false,
'query_var' => true,
'show_in_quick_edit' => true,
'sort' => true,
) );
// Post type repetitor.
register_post_type( 'repetitor', array(
'labels' => array(
'name' => __( 'Repetitors', 'education' ),
'singular_name' => __( 'Repetitor', 'education' ),
'add_new' => __( 'Add Repetitor', 'education' ),
'add_new_item' => __( 'Add new Repetitor', 'education' ),
'edit_item' => __( 'Edit Repetitor', 'education' ),
'new_item' => __( 'New Repetitor', 'education' ),
'view_item' => __( 'View Repetitor', 'education' ),
'search_items' => __( 'Search Repetitor', 'education' ),
'not_found' => __( 'Repetitor not found', 'education' ),
'not_found_in_trash' => __( 'Repetitor not found in trash', 'education' ),
'menu_name' => __( 'Repetitors', 'education' ),
),
'public' => true,
'show_in_rest' => true, // Включает Gutenberg.
'capability_type' => 'post',
'hierarchical' => false,
'has_archive' => 'repetitors',
'rewrite' => array( 'slug' => 'repetitors', 'with_front' => false, 'pages' => true, 'feeds' => false, 'feed' => false ),
'query_var' => true,
'supports' => array( 'page-attributes', 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments', 'custom-fields' ),
'taxonomies' => array( 'repetitor_cat' ),
) );
}rewrite и фильтры post_type_link и term_link $wp_query, проверить можно распечатав этот запросglobal $wp_query;
var_dump( $wp_query );pre_get_postsadd_action( 'pre_get_posts', 'blog_posts' );
function blog_posts( $query ) {
if ( ! is_admin() && $query->is_main_query() && is_page_template( 'blog.php' ) ) {
$query->set( 'post_type', 'post' );
$query->set( 'posts_per_page', '10' );
}
}wp_query(), но учитывайте, что функция пагинации the_posts_navigation() работает только с глобальным запросомfunction get_seo_city() {
$city = get_post_meta( get_the_ID(), '_city', true );
if ( ! $city ) {
$string = 'Город по умолчанию';
}
return $string;
}
// Define the action for register yoast_variable replacments.
function register_custom_yoast_variables() {
wpseo_register_var_replacement( '%%City%%', 'get_seo_city', 'advanced', __( 'Some instead title text', 'wpgen' ) );
}
// Add action.
add_action( 'wpseo_register_extra_replacements', 'register_custom_yoast_variables' );