Written by Anonymous
<?php //カルーセル
/**
* Cocoon WordPress Theme
* @author: yhira
* @link: https://wp-cocoon.com/
* @license: http://www.gnu.org/licenses/gpl-2.0.html GPL v2 or later
*/
if ( !defined( 'ABSPATH' ) ) exit;
if (is_carousel_visible() && !is_amp() && apply_filters('carousel_visible', true)): ?>
<?php //カルーセルに関連付けられた投稿の取得
$args = array(
// 'category__in' => get_carousel_category_ids(),
// 'tag__in' => get_carousel_tag_ids(),
'orderby' => get_carousel_orderby(), //ランダム表示
'no_found_rows' => true,
'posts_per_page' => get_carousel_max_count(),
);
if (is_carousel_popular_posts_enable()) {
// 人気記事
$days = get_carousel_popular_posts_count_days();
$limit = intval(get_carousel_max_count()) * 5;
$category_ids = is_array(get_carousel_category_ids()) ? get_carousel_category_ids() : array();
$records = get_access_ranking_records($days, $limit, 'post');
$post_ids = array();
//取得した投稿IDをセット
foreach ($records as $post) {
$post_ids[] = $post->ID; // 配列に追加
}
$args += array('post__in' => $post_ids);
} else if (!empty(get_carousel_category_ids())) {
// カテゴリー
$args += array('category__in' => get_carousel_category_ids());
} else if (!empty(get_carousel_tag_ids())) {
$args += array('tag__in' => get_carousel_tag_ids());
}
$args = apply_filters('cocoon_carousel_args', $args);
$query = new WP_Query( $args );
// var_dump($query -> have_posts());
// var_dump($query);
if( $query -> have_posts() ): //カルーセルが設定されているとき
?>
<div id="carousel" class="carousel<?php echo get_additional_carousel_area_classes(); ?>">
<div id="carousel-in" class="carousel-in wrap">
<div class="carousel-content cf">
<?php while ($query -> have_posts()) : $query -> the_post(); ?>
<?php //カルーセルカードの取得
cocoon_template_part('tmp/carousel-entry-card'); ?>
<?php endwhile;?>
</div>
</div>
</div>
<?php
endif;
wp_reset_postdata();
?>
<?php endif ?>