Written by Anonymous
//人気ランキングリストの取得
if ( !function_exists( 'generate_popular_entries_tag' ) ):
function generate_popular_entries_tag($atts){
extract(shortcode_atts(array(
'days' => 'all',
'entry_count' => 5,
'entry_type' => ET_DEFAULT,
'ranking_visible' => 0,
'pv_visible' => 0,
'cat_ids' => array(),
'children' => 0,
'exclude_post_ids' => array(),
'exclude_cat_ids' => array(),
'bold' => 0,
'arrow' => 0,
'date' => 0,
'class' => null,
'snippet' => 0,
'author' => null,
'post_type' => 'post',
'horizontal' => 0,
'action' => null,
'comment' => 0,
'offset' => 0,
), $atts, 'generate_popular_entries_tag'));
global $_IS_SWIPER_ENABLE;
if ($horizontal) {
$_IS_SWIPER_ENABLE = true;
}
$offset = max(0, intval($offset));
$total_fetch_count = $offset + intval($entry_count);
$all_records = get_access_ranking_records($days, $total_fetch_count, $entry_type, $cat_ids, $exclude_post_ids, $exclude_cat_ids, $children, $author, $post_type, $snippet);
$records = $all_records ? array_slice($all_records, $offset, $entry_count) : array();
$cards_classes = get_additional_widget_entry_cards_classes(array(
'type' => $entry_type,
'ranking_visible' => $ranking_visible,
'pv_visible' => $pv_visible,
'bold' => $bold,
'arrow' => $arrow,
'class' => $class,
'horizontal' => $horizontal,
'date' => $date,
));
$swiper_slide = $horizontal ? ' swiper-slide' : null;
$counter_style = ($ranking_visible && $offset > 0) ? 'counter-reset: p-rank ' . $offset . ';' : '';
?>
<div class="popular-entry-cards widget-entry-cards no-icon cf<?php echo $cards_classes; ?>"<?php echo $counter_style ? ' style="' . esc_attr( $counter_style ) . '"' : ''; ?>>
<?php if ( $horizontal ) echo '<div class="swiper-wrapper">'; ?>
<?php if ( $records ) :
$i = 1 + $offset;
foreach ($records as $post):
cocoon_template_part('tmp/popular-card', null, array(
'post' => $post,
'index' => $i,
'entry_type' => $entry_type,
'ranking_visible' => $ranking_visible,
'pv_visible' => $pv_visible,
'date' => $date,
'snippet' => $snippet,
'comment' => $comment,
'swiper_slide' => $swiper_slide,
));
$i++;
endforeach;
else :
echo '<p>'.__( '人気記事は見つかりませんでした。', THEME_NAME ).'</p>';
endif; ?>
<?php if ( $horizontal ) : ?>
</div>
<div class="swiper-button-prev"></div>
<div class="swiper-button-next"></div>
<?php endif; ?>
</div>
<?php
}
endif;