Written by Anonymous
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'));
//Swiperスクリプトコードを呼び出すかどうか
global $_IS_SWIPER_ENABLE;
if ($horizontal) {
$_IS_SWIPER_ENABLE = true;
}
// offsetを考慮して取得件数を調整
$total_fetch_count = intval($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);
// offset分を除外して抽出
$records = array();
if ($all_records) {
$records = array_slice($all_records, $offset, $entry_count);
}
$thumb_size = get_popular_entries_thumbnail_size($entry_type);
$atts = array(
'type' => $entry_type,
'ranking_visible' => $ranking_visible,
'pv_visible' => $pv_visible,
'bold' => $bold,
'arrow' => $arrow,
'class' => $class,
'horizontal' => $horizontal,
'date' => $date,
);
$cards_classes = get_additional_widget_entry_cards_classes($atts);
$swiper_slide = null;
if ($horizontal) {
$swiper_slide = ' swiper-slide';
}
// ランキングの開始番号をCSSカウンターに反映させるためのスタイル
$counter_style = $ranking_visible ? ' style="counter-reset: p-rank ' . intval($offset) . ';"' : '';
?>
<div class="popular-entry-cards widget-entry-cards no-icon cf<?php echo $cards_classes; ?>"<?php echo $counter_style; ?>>
<?php if ( $horizontal ) : ?>
<div class="swiper-wrapper">
<?php endif; ?>
<?php if ( $records ) :
$i = 1 + intval($offset);
foreach ($records as $post):
$permalink = get_permalink( $post->ID );
$title = $post->post_title;
$no_thumbnail_url = ($entry_type == ET_DEFAULT) ? get_no_image_120x68_url($post->ID) : get_no_image_320x180_url($post->ID);
$w = ($entry_type == ET_DEFAULT) ? THUMB120WIDTH : THUMB320WIDTH;
$h = ($entry_type == ET_DEFAULT) ? THUMB120HEIGHT : THUMB320HEIGHT;
$post_thumbnail = get_the_post_thumbnail( $post->ID, $thumb_size, array('alt' => '') );
$pv = $post->sum_count;
if ($post_thumbnail) {
$post_thumbnail_img = $post_thumbnail;
} else {
$post_thumbnail_img = get_original_image_tag($no_thumbnail_url, $w, $h, 'no-image popular-entry-card-thumb-no-image widget-entry-card-thumb-no-image', '');
}
//スニペット表示
$snippet_tag = '';
//「タイトルを重ねた大きなサムネイル」の時はスニペットを表示させない
if ($snippet && isset($post->ID) && isset(get_post($post->ID)->post_content) && $entry_type !== ET_LARGE_THUMB_ON) {
$snippet_tag = '<div class="popular-entry-card-snippet widget-entry-card-snippet card-snippet">'.get_the_snippet(get_post($post->ID)->post_content, get_entry_card_excerpt_max_length(), $post->ID).'</div>';
}
$pv_tag = null;
if ($pv_visible){
$pv_unit = ($pv == '1') ? 'view' : 'views';
// $pv_unit = apply_filters('popular_entry_card_pv_unit', $pv_unit, $pv);
$pv_text = $pv.' '.$pv_unit;
$pv_text = apply_filters('popular_entry_card_pv_text', $pv_text, $pv, $pv_unit);
$pv_tag = '<span class="popular-entry-card-pv widget-entry-card-pv">'.$pv_text.'</span>';
}
?>
<a href="<?php echo $permalink; ?>" class="popular-entry-card-link widget-entry-card-link a-wrap no-<?php echo $i; ?><?php echo $swiper_slide; ?>" title="<?php echo esc_attr(escape_shortcodes($title)); ?>">
<div <?php post_class( array('post-'.$post->ID, 'popular-entry-card', 'widget-entry-card', 'e-card', 'cf'), $post->ID ); ?>>
<figure class="popular-entry-card-thumb widget-entry-card-thumb card-thumb">
<?php echo $post_thumbnail_img; ?>
<?php
$is_visible = apply_filters('is_popular_entry_card_category_label_visible', false);
$is_visible = apply_filters('is_widget_entry_card_category_label_visible', $is_visible);
the_nolink_category($post->ID, $is_visible); //カテゴリーラベルの取得 ?>
</figure><!-- /.popular-entry-card-thumb -->
<div class="popular-entry-card-content widget-entry-card-content card-content">
<div class="popular-entry-card-title widget-entry-card-title card-title"><?php echo escape_shortcodes($title);?></div>
<?php echo $snippet_tag; ?>
<?php if ($entry_type != ET_LARGE_THUMB_ON): ?>
<?php echo $pv_tag; ?>
<?php endif ?>
<?php do_action( 'widget_entry_card_date_before', 'popular', $post->ID); ?>
<div class="popular-entry-card-meta widget-entry-card-meta card-meta">
<div class="popular-entry-card-info widget-entry-card-info card-info">
<?php generate_widget_entry_card_date('popular', $post->ID, $display = $date);
if ($comment): ?>
<span class="popular-entry-card-comment widget-entry-card-comment card-comment post-comment-count"><span class="fa fa-comment-o comment-icon" aria-hidden="true"></span><?php echo get_comments_number( $post->ID ); ?></span>
<?php endif; ?>
</div>
</div>
</div><!-- /.popular-entry-content -->
<?php if ($entry_type == ET_LARGE_THUMB_ON): ?>
<?php echo $pv_tag; ?>
<?php endif ?>
</div><!-- /.popular-entry-card -->
</a><!-- /.popular-entry-card-link -->
<?php
$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
}