Written by Anonymous
//ウィジェットエントリーカードリンクタグの取得
if ( !function_exists( 'get_widget_entry_card_link_tag' ) ):
function get_widget_entry_card_link_tag($atts){
extract(shortcode_atts(array(
'prefix' => WIDGET_NEW_ENTRY_CARD_PREFIX,
'url' => null,
'title' => null,
'snippet' => null,
'date' => null,
'thumb_size' => null,
'image_attributes' => null,
'ribbon_no' => null,
'type' => null,
'classes' => null,
'object' => 'post',
'object_id' => null,
'horizontal' => 0,
'target' => null,
), $atts, 'get_widget_entry_card_link_tag'));
$class_text = null;
if (isset($classes[0]) && !empty($classes[0])) {
$class_text = ' '.implode(' ', $classes);
}
//リボンタグの取得
$ribbon_tag = get_navi_card_ribbon_tag($ribbon_no);
$swiper_slide = null;
if ($horizontal) {
$swiper_slide = ' swiper-slide';
}
// クラスの初期配列
$base_classes = [
$prefix . '-entry-card',
'widget-entry-card',
'e-card',
'cf'
];
if ($prefix === WIDGET_NAVI_ENTRY_CARD_PREFIX) {
$post_types = get_custum_post_types();
if ($object === 'post' || $object === 'page' || in_array($object, $post_types)) {
// 投稿・固定ページ・カスタム投稿のみ
$classes = get_post_class(array_merge(['post-' . $object_id], $base_classes), $object_id);
} else {
$classes = $base_classes;
}
} else {
$classes = get_post_class(array_merge(['post-' . get_the_ID()], $base_classes));
}
// クラス属性として出力
$div_class = 'class="' . implode(' ', $classes) . '"';
// target 属性の設定
$target_attr = $target ? ' target="' . esc_attr($target) . '"' : '';
ob_start(); ?>
<a href="<?php echo esc_url($url); ?>" class="<?php echo $prefix; ?>-entry-card-link widget-entry-card-link a-wrap<?php echo $class_text; ?><?php echo $swiper_slide; ?>" title="<?php echo esc_attr(escape_shortcodes($title)); ?>"<?php echo $target_attr; ?>>
<div <?php echo $div_class; ?>>
<?php echo $ribbon_tag; ?>
<figure class="<?php echo $prefix; ?>-entry-card-thumb widget-entry-card-thumb card-thumb">
<?php //$prefixがnaviのとき
if (is_widget_navi_entry_card_prefix($prefix)) {
$class = 'navi-entry-card-image widget-entry-card-image card-thumb';
//投稿・固定ページ・カスタム投稿の場合
$post_types = get_custum_post_types();
if ($object === 'post' || $object === 'page' || in_array($object, $post_types)) {
// 投稿タイトル再取得
$title = get_the_title($object_id);
if ($type === ET_DEFAULT) {
$size = THUMB120;
} else {
$size = THUMB320;
}
$attr = array();
$attr['class'] = $class;
$thumbnail_tag = get_the_post_thumbnail( $object_id, $size, $attr );
if ($thumbnail_tag) {
echo $thumbnail_tag;
} else {
echo get_widget_entry_card_no_image_tag(ET_DEFAULT, $prefix);
}
} else {
if ($object === 'category') {
//カテゴリーの場合
$class = 'category-image '.$class;
if (!get_the_category_eye_catch_url($object_id)) {
//NO IMAGEの場合
$class = 'no-image '.$class;
}
}
echo get_navi_entry_card_thumbnail_tag($image_attributes, $title, $class);
}
} else {
//新着記事・関連記事など
echo get_widget_entry_card_thumbnail_tag($prefix, $thumb_size, $type);
}
?>
</figure><!-- /.entry-card-thumb -->
<div class="<?php echo $prefix; ?>-entry-card-content widget-entry-card-content card-content">
<div class="<?php echo $prefix; ?>-entry-card-title widget-entry-card-title card-title"><?php echo $title;?></div>
<?php if ($snippet): ?>
<div class="<?php echo $prefix; ?>-entry-card-snippet widget-entry-card-snippet card-snippet"><?php echo $snippet; ?></div>
<?php endif; ?>
<?php
if (!is_widget_navi_entry_card_prefix($prefix)) {
generate_widget_entry_card_date($prefix, null, $display = $date);
} ?>
</div><!-- /.entry-content -->
</div><!-- /.entry-card -->
</a><!-- /.entry-card-link -->
<?php
return ob_get_clean();
}
endif;