Written by Anonymous
//ユーザー別の最新記事 if (!shortcode_exists('author_new_list')) {//関数名変更 add_shortcode('author_new_list', 'author_new_list');//関数名変更 } if ( !function_exists( 'author_new_list' ) )://関数名変更 function author_new_list($atts) {//関数名変更 extract(shortcode_atts(array( 'count' => 5, 'cats' => 'all', 'tags' => null, 'type' => 'default', 'children' => 0, 'post_type' => 'post', 'taxonomy' => 'category', 'sticky' => 0, 'random' => 0, 'modified' => 0, 'order' => 'desc', 'action' => null, 'bold' => 0, 'arrow' => 0, 'class' => null, 'snippet' => 0, 'author' => null,//付け加え ), $atts, 'author_new_list'));//関数名変更 //カテゴリを配列化 $cat_ids = array(); if ($cats && $cats != 'all') { $cat_ids = explode(',', $cats); } //タグを配列化 $tag_ids = array(); if ($tags && $tags != 'all') { $tag_ids = explode(',', $tags); } //引数配列のセット $atts = array( 'entry_count' => $count, 'cat_ids' => $cat_ids, 'tag_ids' => $tag_ids, 'type' => $type, 'include_children' => $children, 'post_type' => $post_type, 'taxonomy' => $taxonomy, 'sticky' => $sticky, 'random' => $random, 'modified' => $modified, 'order' => $order, 'action' => $action, 'bold' => $bold, 'arrow' => $arrow, 'class' => $class, 'snippet' => $snippet, 'author' => $author,//付け加え ); ob_start(); generate_widget_entries_tag_author($atts);//関数名変更 $res = ob_get_clean(); return $res; } endif; if ( !function_exists( 'generate_widget_entries_tag_author' ) )://関数名変更 function generate_widget_entries_tag_author($atts){//関数名変更 extract(shortcode_atts(array( 'entry_count' => 5, 'cat_ids' => array(), 'tag_ids' => array(), 'type' => ET_DEFAULT, 'include_children' => 0, 'post_type' => null, 'taxonomy' => 'category', 'sticky' => 0, 'random' => 0, 'modified' => is_get_index_sort_orderby_modified(), 'order' => 'desc', 'action' => null, 'exclude_cat_ids' => array(), 'bold' => 0, 'arrow' => 0, 'class' => null, 'snippet' => 0, 'author' => null,//付け加え ), $atts)); global $post; //ランダムが有効な時は関連記事 if ($random) { $prefix = WIDGET_RELATED_ENTRY_CARD_PREFIX; } else { $prefix = WIDGET_NEW_ENTRY_CARD_PREFIX; } $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 ($author){//付け加え $args += array( 'author' => $author, ); } //除外カテゴリー $exclude_category_ids = get_archive_exclude_category_ids(); if ($exclude_category_ids && is_array($exclude_category_ids)) { $args += array( 'category__not_in' => $exclude_category_ids, ); } //除外投稿 $exclude_post_ids = get_archive_exclude_post_ids(); if ($exclude_post_ids && is_array($exclude_post_ids)) { $args += array( 'post__not_in' => $exclude_post_ids, ); } if ($post_type) { $args += array( 'post_type' => explode(',', $post_type) ); } if ($random && $modified) { $args += array( 'orderby' => array('rand', 'modified'), ); } else { if ($random) { $args += array( 'orderby' => 'rand', ); } if ($modified) { $args += array( 'orderby' => 'modified', ); } } //関連記事の場合は表示ページを除外 if ($random) { $post_id = get_the_ID(); if (isset($args['post__not_in'])) { $args['post__not_in'][] = $post_id; } else { $args['post__not_in'] = array($post_id); } } //除外カテゴリーの設定 if (!empty($exclude_cat_ids)) { // _v($cat_ids); // _v($exclude_cat_ids); $cat_ids = array_diff($cat_ids, $exclude_cat_ids); // _v($cat_ids); } //カテゴリー・タグの指定 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) { // _v($taxonomy); // _v($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); $thumb_size = get_widget_entries_thumbnail_size($type); if ($random) { $args = apply_filters('widget_related_entries_args', $args); $thumb_size = apply_filters('get_related_entries_thumbnail_size', $thumb_size, $type); } else { $args = apply_filters('widget_new_entries_args', $args); $thumb_size = apply_filters('get_new_entries_thumbnail_size', $thumb_size, $type); } $args = apply_filters('widget_entries_args', $args); //_v($args); //query_posts( $args ); //クエリの作成 $query = new WP_Query( $args ); $atts = array( 'type' => $type, 'bold' => $bold, 'arrow' => $arrow, 'class' => $class, ); $cards_classes = get_additional_widget_entry_cards_classes($atts); ?> <div class="<?php echo $prefix; ?>-entry-cards widget-entry-cards no-icon cf<?php echo $cards_classes; ?>"> <?php //if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <?php if ( $query -> have_posts() ) : while ( $query -> have_posts() ) : $query -> the_post(); ?> <?php //エントリーカードリンクタグの生成 $atts = array( 'prefix' => $prefix, 'url' => get_the_permalink(), 'title' => get_the_title(), 'thumb_size' => $thumb_size, 'type' => $type, ); if ($snippet) { $atts += array( 'snippet' => get_the_snippet( get_the_content(''), get_entry_card_excerpt_max_length() ), ); } //var_dump($atts); echo get_widget_entry_card_link_tag($atts); ?> <?php endwhile; else : echo '<p>'.__( '記事は見つかりませんでした。', THEME_NAME ).'</p>';//見つからない時のメッセージ endif; ?> <?php wp_reset_postdata(); ?> <?php //wp_reset_query(); ?> </div> <?php } endif;