get_terms()
есть ключ parent, по которому можно проверить наличие родительской категории$categories = get_terms();
foreach ( $categories as $key => $category ) {
if ( $category->parent == 0 ) {
# нет родителя
} else {
# есть родитель
}
}
function is_category_parent( $cat_id ) {
$category = get_category( $cat_id );
if ( $category->parent == 0 ) {
return true;
}
return false;
}
if ( is_category_parent( $cat_id ) ) {
// категория имеет родителя
}
Walker_Nav_Menu()
wp_get_nav_menu_items()
и собрать простым циклом$menu_name = 'custom_menu_slug';
$locations = get_nav_menu_locations();
// получаем элементы меню
$menu_items = wp_get_nav_menu_items( $locations[ $menu_name ] );
// создаем список
echo '<ul id="menu-' . $menu_name . '">';
foreach ( (array) $menu_items as $key => $menu_item ){
echo '<li><a href="' . $menu_item->url . '">' . $menu_item->title . '</a></li>';
}
echo '</ul>';
get_posts()
абсолютно не нужноis_tag()
и is_category()
так же нужны, т.к. шаблоны tag.php и category.php уже загружаются по этим условиям<?php get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<header class="page-header">
<?php
the_archive_title( '<h1 class="page-title">', '</h1>' );
the_archive_description( '<div class="taxonomy-description">', '</div>' );
?>
</header><!-- .page-header -->
<?php
// Start the loop.
while ( have_posts() ) :
the_post();
get_template_part( 'template-parts/content', get_post_format() );
// End the loop.
endwhile;
// Previous/next page navigation.
the_posts_pagination(
array(
'prev_text' => __( 'Previous page', 'twentysixteen' ),
'next_text' => __( 'Next page', 'twentysixteen' ),
'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentysixteen' ) . ' </span>',
)
);
// If no content, include the "No posts found" template.
else :
get_template_part( 'template-parts/content', 'none' );
endif; ?>
</main><!-- .site-main -->
</div><!-- .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
$queried_object = get_queried_object();
if ( is_tax( 'projects' ) && isset( $queried_object->term_id ) ) {
$query = new WP_Query( [
'post_type' => 'portfolio',
'posts_per_page' => 10,
'tax_query' => [
[
'taxonomy' => 'projects',
'field' => 'id',
'terms' => $queried_object->term_id,
],
]
] );
}
$classes[] = 'project-item col-lg-4 col-md-6 col-sm-12';
$project_taxes = get_the_terms( $post->ID, 'project_tax' );
if( is_array( $project_taxes ) ) {
foreach ( $project_taxes as $key => $project_tax ) {
$classes[] = $project_tax->slug;
}
}
echo '<div class="' . implode( ' ', $classes ) . '">';
echo '<h2>' . $post->post_title . '</h2>';
echo '</div>';
PHP-код, встроенный в страницу будет разбирать строку GET-запроса от API сервиса бронирования и, на основании данных из запроса, формировать сообщение о результате бронирования.
if ( $condition ) {
get_template_part( 'templates/thankyou' );
} else {
get_template_part( 'templates/common' );
}
the_content
add_filter( 'the_content', 'custom_content' );
function custom_content( $text ) {
$ads = '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1452282254312739" crossorigin="anonymous"></script>';
return $ads . $text;
}
if ( get_post_type() === 'post' ) {
return $ads . $text;
} else {
return $text . $ads;
}
jQuery(document).ready(function ($) {
$('a.tab').on('click', function (e) {
$.ajax({
type: 'POST',
url: wpz_ajax_obj.ajaxurl, // Путь к файлу admin-ajax.php
data: {
'action': 'wpz_ajax_request', // Событие к которому будем обращаться
'post_type': $(e.currentTarget).attr('data-type'), // Передаём тип записи
'security': wplb_ajax_obj.nonce, // Используем nonce для защиты
}
})
e.preventDefault();
});
});
wp_send_json_success()
function wpz_ajax_request() {
if ( isset( $_POST ) ) {
// Проверяем nonce, а в случае если что-то пошло не так, то прерываем выполнение функции
if ( !wp_verify_nonce( $_POST['security'], 'wpz-nonce' ) ) {
wp_die( 'Базовая защита не пройдена' );
}
// заказываем посты из базы
if ( isset( $_POST['post_type'] ) ) {
$args = array(
'post_type' => sanitize_text_field( $_POST['post_type'] ),
'posts_per_page' => 1,
);
$post_query = new WP_Query( $args );
if ( $post_query ) {
# если записи есть, возвращаем в wp_send_json_success() html-постов
} else {
# если записей нет, возвращаем в wp_send_json_success() информацию о том, что их нет
}
} else {
wp_send_json_error();
}
} // end if isset( $_POST )
wp_die();
}
register_post_type()
или Custom Post Type UI14:00 — 21:00; 11:00 — 21:00; 11:00 — 21:00; 11:00 — 21:00; 11:00 — 22:00; 09:00 — 22:00; 09:00 — 21:00
mon="14:00 — 21:00" tue="11:00 — 21:00" wed="11:00 — 21:00" thu="11:00 — 21:00" fri="11:00 — 22:00" sat="09:00 — 22:00" sun="09:00 — 21:00"
$html = str_get_html( get_the_content() );
$links = $html->find( 'a' );
foreach ( $links as $key => $link ) {
var_dump( $link->href );
}
unset( $html );
$link->outertext = '[link]' . $link->outertext . '[/link]';
wp_update_post()