wp_enqueue_style()
и wp_enqueue_script()
wp_enqueue_style( 'my-style', get_template_directory_uri() . '/css/style.css', array(), '1.0.1' );
wp_enqueue_script( 'my-script', get_template_directory_uri() . '/js/script.js', array(), '1.0.1', true );
register_nav_menus()
, подключить вывод в теме wp_nav_menu()
register_sidebar()
, вывод в коде dynamic_sidebar()
, для создания своих виджетов см. функции register_widget()
и класс WP_Widget
wp_enqueue_script()
и стилей wp_enqueue_style()
на хуке wp_enqueue_scripts
woocommerce_register_taxonomy
до регистрации всех таксономий$attribute_taxonomies = wc_get_attribute_taxonomies();
if ( $attribute_taxonomies ) {
foreach ( $attribute_taxonomies as $tax ) {
$name = wc_attribute_taxonomy_name( $tax->attribute_name );
if ( $name ) {
// ...
register_taxonomy( $name, apply_filters( "woocommerce_taxonomy_objects_{$name}", array( 'product' ) ), apply_filters( "woocommerce_taxonomy_args_{$name}", $taxonomy_data ) );
}
}
}
woocommerce_after_register_taxonomy
function register_services_strings() {
if ( function_exists( 'pll_register_string' ) {
pll_register_string( 'Services', 'Услуги' );
pll_register_string( 'Service', 'Услуга' );
}
}
add_action( 'init', 'register_services_strings' );
'has_archive' => 'books'
'rewrite' => array( 'slug' => 'book' )
is_post_type_archive()
get_terms()
нет аргумента post_type, а у WP_Query
аргумента taxonomyget_the_terms()
или has_term()
<ul>
<?php
// Получаем все термины таксономии 'union'
$cats = get_terms(array('taxonomy' => 'union', 'hide_empty' => false));
// Цикл по терминам таксономии
foreach ($cats as $cat) { ?>
<li>
<h2>
<a href="<?php echo get_term_link($cat); ?>">
<?php echo get_field('eu-members') . ' ' . $cat->name . ' <small>🡢 ' . get_field('eu-show-more') . '</small>' ?>
</a>
</h2>
<ul>
<?php
// Создаем новый WP_Query для получения постов текущего термина
$query_city = new WP_Query(array(
'posts_per_page' => -1,
'order' => 'ASC',
'post_type' => 'city',
'tax_query' => array(
array(
'taxonomy' => 'union', // Таксономия
'field' => 'term_id', // Поле термина
'terms' => $cat->term_id, // ID термина
),
),
));
// Проверяем наличие постов
if ($query_city->have_posts()) {
while ($query_city->have_posts()) {
$query_city->the_post(); ?>
<li>
<figure><?php the_post_thumbnail(); ?></figure>
<div>
<span><?php the_title(); ?></span>
</div>
</li>
<?php }
} else {
echo '<li>No posts found.</li>';
}
// Сбрасываем данные поста
wp_reset_postdata();
?>
</ul>
</li>
<?php } ?>
</ul>
$query->set( 'meta_query', array(
'relation' => 'OR',
'actual' => array(
'key' => '_start_date',
'value' => date( 'Y-m-d' ),
'compare' => '>=',
'type' => 'DATE',
),
'completed' => array(
'key' => '_start_date',
'value' => date( 'Y-m-d' ),
'compare' => '<',
'type' => 'DATE'
),
) );
$query->set( 'orderby', array(
'actual' => 'DESC',
'completed' => 'ASC',
) );
pre_get_document_title
if ( ! function_exists( 'pre_get_document_title_callback' ) ) {
/**
* Function for `pre_get_document_title` filter-hook.
*
* @param string $title The document title.
*
* @return string
*/
function pre_get_document_title_callback( $title ) {
if ( is_front_page() ) {
$title = 'Другой заголовок для главной';
}
return $title;
}
}
add_filter( 'pre_get_document_title', 'pre_get_document_title_callback' );
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<?php get_template_part( 'template-parts/content/content' ); ?>
<?php endwhile; ?>
<?php else : ?>
<?php get_template_part( 'template-parts/content/content-none' ); ?>
<?php endif; ?>
if ( ! function_exists( 'init_register_post_types_callback' ) ) {
/**
* Function for 'init` action-hook.
*
* @return void
*/
function init_register_post_types_callback() {
register_taxonomy( 'city', array( 'human' ), array(
'labels' => array(
'name' => _x( 'Cities', 'taxonomy general name', 'domainname' ),
'singular_name' => _x( 'City', 'taxonomy singular name', 'domainname' ),
'search_items' => __( 'Search city', 'domainname' ),
'popular_items' => __( 'Popular cities', 'domainname' ),
'all_items' => __( 'All cities', 'domainname' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit city', 'domainname' ),
'update_item' => __( 'Update city', 'domainname' ),
'add_new_item' => __( 'Add new city', 'domainname' ),
'new_item_name' => __( 'New city', 'domainname' ),
'separate_items_with_commas' => __( 'Separate city with commas', 'domainname' ),
'add_or_remove_items' => __( 'Add or remove city', 'domainname' ),
'choose_from_most_used' => __( 'Choose from the most used cities', 'domainname' ),
'menu_name' => __( 'Cities', 'domainname' ),
),
'public' => true,
'show_in_nav_menus' => false,
'show_in_rest' => true,
'show_in_quick_edit' => true,
'sort' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'city', 'hierarchical' => false, 'with_front' => false, 'feed' => false ),
'show_admin_column' => true,
) );
register_taxonomy( 'activity', array( 'human' ), array(
'labels' => array(
'name' => _x( 'Activities', 'taxonomy general name', 'domainname' ),
'singular_name' => _x( 'Activity', 'taxonomy singular name', 'domainname' ),
'search_items' => __( 'Search activities', 'domainname' ),
'all_items' => __( 'All activities', 'domainname' ),
'parent_item' => __( 'Parent activities', 'domainname' ),
'parent_item_colon' => __( 'Parent activities:', 'domainname' ),
'edit_item' => __( 'Edit activities', 'domainname' ),
'update_item' => __( 'Update activities', 'domainname' ),
'add_new_item' => __( 'Add new activities', 'domainname' ),
'new_item_name' => __( 'New activities Name', 'domainname' ),
'menu_name' => __( 'Activities', 'domainname' ),
),
'public' => true,
'show_in_nav_menus' => false,
'show_in_rest' => true,
'show_in_quick_edit' => true,
'sort' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'activity', 'hierarchical' => false, 'with_front' => false, 'feed' => false ),
'show_admin_column' => true,
) );
register_post_type( 'human', array(
'labels' => array(
'name' => __( 'Humans', 'domainname' ),
'singular_name' => __( 'Human', 'domainname' ),
'add_new' => __( 'Add human', 'domainname' ),
'add_new_item' => __( 'Add new human', 'domainname' ),
'edit_item' => __( 'Edit human', 'domainname' ),
'new_item' => __( 'New human', 'domainname' ),
'view_item' => __( 'View human', 'domainname' ),
'search_items' => __( 'Search human', 'domainname' ),
'not_found' => __( 'Human not found', 'domainname' ),
'not_found_in_trash' => __( 'Human not found in trash', 'domainname' ),
'menu_name' => __( 'Human', 'domainname' ),
),
'public' => true,
'show_in_rest' => true,
'capability_type' => 'post',
'hierarchical' => false,
'has_archive' => 'humans',
'rewrite' => array( 'slug' => 'humans', '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( 'activities' ),
) );
}
}
add_action( 'init', 'init_register_post_types_callback' );
/** The name of the database for WordPress */
define( 'DB_NAME', 'db_name' );
/** Database username */
define( 'DB_USER', 'root' );
/** Database password */
define( 'DB_PASSWORD', '' );
/** Database hostname */
define( 'DB_HOST', 'localhost' );
register_post_type()