В предыдущем посте подробная инструкция про слайдер для шаблона Newsmatic.
Сегодня поправим слайдер для схожего шаблона Worpress - Newsxo
Переходим в файл слайдера public_html/wp-content/themes/newsxo/inc/ansar/hooks/blocks/block-banner-list.php
и перед открывающим div добавим:<?php // Получаем 3 записи с тегом "top" $newsxo_all_posts_main = new WP_Query(array( 'posts_per_page' => 3, 'tag' => 'top', // slug тега 'post_status' => 'publish', 'ignore_sticky_posts' => true, )); ?>Добавляем метку со слагом top и присваиваем любимым 3 записям.
Супер.
Чтобы в этом же шаблоне сделать в виджете статьи записи рандомно (в плагине Newsxo_Posts_List - AR: Posts List)Нужно закоментить правило выбора категории и добавить в этот php следующее в файл public_html/wp-content/themes/newsxo/inc/ansar/widgets/widget-posts-list.php:
<?php // $all_posts = newsxo_get_posts($number_of_posts, $category); $all_posts = new WP_Query(array( 'posts_per_page' => (int) $number_of_posts, 'cat' => (int) $category, 'post_status' => 'publish', 'orderby' => 'rand', 'no_found_rows' => true, 'ignore_sticky_posts' => true, )); $count = 1; if ($all_posts->have_posts()) :
Справа блок с 4 статьями возле слайдера показывает рандомно?
Для того чтобы сделать записи справа рандомно нужно в файле подменить запрос внутри функции на WP_Query с 'orderby' => 'rand'.
/public_html/wp-content/themes/newsxo/inc/ansar/hooks/blocks/featured/featured-default.phpполный код выглядит так:
<?php if (!function_exists('newsxo_latest_posts')) : /** * Выводит 4 случайные записи из выбранной категории * @since newsxo */ function newsxo_latest_posts() { $slider_meta_enable = get_theme_mod('slider_meta_enable', 'true'); $select_latest_news_category = newsxo_get_option('select_latest_news_category'); // Запрос случайных записей $featured_latest_posts = new WP_Query(array( 'posts_per_page' => 4, 'cat' => $select_latest_news_category, 'post_status' => 'publish', 'orderby' => 'rand', 'ignore_sticky_posts' => true, )); ?> <div class="col-lg-6 prav"> <div class="multi-post-widget mb-0 mt-3 mt-lg-0"> <div class="inner_columns five"> <?php if ($featured_latest_posts->have_posts()) : while ($featured_latest_posts->have_posts()) : $featured_latest_posts->the_post(); global $post; $newsxo_url = newsxo_get_freatured_image_url($post->ID, 'newsxo-slider-full'); $url = !empty($newsxo_url) ? 'style="background-image: url(' . esc_url($newsxo_url) . ');"' : ''; ?> <div class="bs-blog-post three bsm bshre post-1 mb-0"> <figure class="bs-thumb-bg back-img" <?php echo $url; ?>></figure> <a class="link-div" href="<?php the_permalink(); ?>"></a> <div class="inner"> <?php if($slider_meta_enable == true) { newsxo_post_categories(); } ?> <h4 class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4> <?php if($slider_meta_enable == true) { newsxo_post_meta(); } ?> </div> </div> <?php endwhile; wp_reset_postdata(); endif; ?> </div> </div> </div> <?php } endif; add_action('newsxo_action_latest_posts', 'newsxo_latest_posts');