function owl_slider_shortcode( $atts ) {
// белый список параметров и значения по умолчанию для шорткода
$atts = shortcode_atts( array(
'category' => '',
'numberposts' => 10,
), $atts );
$html = '';
$myposts = get_posts([
'numberposts' => $atts['numberposts'],
'category' => $atts['category'],
]);
if ( $myposts ) {
$html .= '<div class="owl-menu owl-carousel custom-owl-carousel owl-theme">';
$html .= '<div class="item-slider">';
$html .= '<div class="item-menu">';
foreach ( $myposts as $post ) {
setup_postdata( $post );
$html .= '<span class="post-date">' . get_the_date() . '</span>';
$html .= '<h3 class="post-title">' . get_the_title() . '</h3>';
$html .= '<a class="box-post_link" href="' . get_permalink() . '">Читать дальше</a>';
}
wp_reset_postdata(); // сбрасываем $post
$html .= '</div>';
$html .= '</div>';
$html .= '</div>';
}
return $html;
}
add_shortcode( 'owl-slider', 'owl_slider_shortcode');
<?php
/*
Template Name: Мой шаблон страницы
*/
?>
<!-- Здесь html/php код шаблона -->
wp_insert_category()
foreach ( $variable as $key => $value ) {
$term_args = array(
'cat_ID' => $value['term_id'],
'cat_name' => $value['term_title'],
'category_description' => '',
'category_nicename' => $value['term_slug'],
'category_parent' => '',
'taxonomy' => 'category'
);
$term_id = wp_insert_category( $term_args );
}
/* Add Dashicons in WordPress Front-end */
add_action( 'wp_enqueue_scripts', 'load_dashicons_front_end' );
function load_dashicons_front_end() {
wp_enqueue_style( 'dashicons' );
}
function my_styles_method() {
wp_enqueue_style('custom-main', get_template_directory_uri() . '/css/main.css');
if ( is_page( 422 ) ) {
wp_enqueue_style('custom-menu', get_template_directory_uri() . '/css/mmenu.css');
wp_enqueue_style('custom-select', get_template_directory_uri() . '/css/nice-select.css');
wp_enqueue_style('custom-style', get_template_directory_uri() . '/css/style.css');
}
}
add_action( 'wp_enqueue_scripts', 'my_styles_method' );
// задаем нужные нам критерии выборки данных из БД
$args = array(
'posts_per_page' => 5,
'post_type' => 'post',
);
$query = new WP_Query( $args );
// Цикл
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
get_template_part( 'template-parts/content', get_post_type() );
}
} else {
// Постов не найдено
get_template_part( 'template-parts/content', 'none' );
}
// Возвращаем оригинальные данные поста. Сбрасываем $post
wp_reset_postdata();
wp_add_inline_script()
или добавить еще один js-файл и подключить его. Попробуйтеfunction creamin_load_scripts() {
wp_enqueue_script( 'exdent-script', get_theme_file_uri( '/assets/js/jquery.exdent.min.js' ), array( 'jquery' ), null, true );
$exdent_init = "jQuery(function($) {
$('blockquote, q').exdent({
by: '.5em'
});
});";
wp_add_inline_script( 'exdent-script', $exdent_init );
}
add_action( 'wp_enqueue_scripts', 'creamin_load_scripts' );
wp_enqueue_scripts
указывать не нужно