//新着記事と人気記事のファンクション function generate_widget_entries_tag($atts){ extract(shortcode_atts(array( 'entry_count' => 5, 'cat_ids' => array(), 'tag_ids' => array(), 'entry_type' => ET_DEFAULT, 'include_children' => 0, 'post_type' => null, 'taxonomy' => 'category', 'sticky' => 0, 'random' => 0, 'order' => 'desc', 'action' => null, ), $atts)); //ランダムが有効な時は関連記事 if ($random) { $prefix = 'widget-related'; } else { $prefix = 'new'; }
$args = array( 'posts_per_page' => $entry_count, 'no_found_rows' => true, 'action' => $action, ); if (!$sticky) { $args += array( 'post__not_in' => get_sticky_post_ids(), ); } if ($order) { $args += array( 'order' => strtoupper($order), ); } if ($post_type) { $args += array( 'post_type' => explode(',', $post_type) ); } if ($random) { $args += array( 'orderby' => 'rand' ); } if ( $cat_ids || $tag_ids ) { //_v($cat_ids); $tax_querys = array(); if ($cat_ids) { $tax_querys[] = array( 'taxonomy' => $taxonomy, 'terms' => $cat_ids, 'include_children' => $include_children, 'field' => 'term_id', 'operator' => 'IN' ); } if ($tag_ids) { $tax_querys[] = array( 'taxonomy' => 'post_tag', 'terms' => $tag_ids, 'field' => 'term_id', 'operator' => 'IN' ); } //_v($tax_querys); $args += array( 'tax_query' => array( $tax_querys, 'relation' => 'AND' ) );
} // _v($args); if ($random) { $args = apply_filters('widget_related_entries_args', $args); } else { $args = apply_filters('widget_new_entries_args', $args); } $args = apply_filters('widget_entries_args', $args); //_v($args); $thumb_size = get_widget_entries_thumbnail_size($entry_type); //query_posts( $args ); //クエリの作成 $query = new WP_Query( $args ); ?> <div class="<?php echo $prefix; ?>-entry-cards widget-entry-cards no-icon cf<?php echo get_additional_widget_entriy_cards_classes($entry_type); ?>"> <?php //if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if ( $query -> have_posts() ) : while ( $query -> have_posts() ) : $query -> the_post(); ?> <a href="<?php the_permalink(); ?>" class="<?php echo $prefix; ?>-entry-card-link widget-entry-card-link a-wrap" title="<?php the_title(); ?>"> <div class="<?php echo $prefix; ?>-entry-card widget-entry-card e-card cf"> <figure class="<?php echo $prefix; ?>-entry-card-thumb widget-entry-card-thumb card-thumb"> <?php if ( has_post_thumbnail() ): // サムネイルを持っているときの処理 ?> <?php the_post_thumbnail( $thumb_size, array('alt' => '') ); ?> <?php else: // サムネイルを持っていないときの処理
$url = ($entry_type == ET_DEFAULT) ? get_no_image_120x68_url() : get_no_image_320x180_url();
$w = ($entry_type == ET_DEFAULT) ? THUMB120WIDTH : THUMB320WIDTH;
$h = ($entry_type == ET_DEFAULT) ? THUMB120HEIGHT : THUMB320HEIGHT;
?>
<img src="<?php echo $url; ?>" alt="" class="no-image <?php echo $prefix; ?>-entry-card-thumb-no-image widget-entry-card-thumb-no-image" width="<?php echo $w; ?>" height="<?php echo $h; ?>" />
<?php endif; ?>
<?php the_nolink_category(null, false); //カテゴリラベルの取得 ?>
</figure><!-- /.new-entry-card-thumb -->
<?php
$days = 7; //Newを表示させたい期間の日数
$today = date_i18n('U');
$entry = get_the_time('U');
$kiji = date('U',($today - $entry)) / 86400 ;
if( $days > $kiji ){
echo '<span class="badge badge-red">New</span>';
}
?>
<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 the_title();?></div>
<?php generate_widget_entry_card_date($prefix); ?>
</div><!-- /.new-entry-content -->
</div><!-- /.new-entry-card -->
</a><!-- /.new-entry-card-link --> <?php endwhile; else : echo '<p>'.__( '記事は見つかりませんでした。', THEME_NAME ).'</p>';//見つからない時のメッセージ endif; ?> <?php wp_reset_postdata(); ?> <?php //wp_reset_query(); ?> </div> <?php }