iguigu
フォーラムへの返信
-
フォーラム: 使い方全般
返信が含まれるトピック: jquery autopager 1ページ目が読み込まれるフォーラム: 使い方全般
返信が含まれるトピック: 記事がなかったら祖先タームから取得方法フォーラム: 使い方全般
返信が含まれるトピック: 記事がなかったら祖先タームから取得方法階層構造の理解が乏しかったです。
ありがとうございます。
あともう1点だけ教えてください。$i=0; $i++;
上記のコードでランキングの順位を出しているのですが、
階層でループした時に、 1 2 1 2 3と順位の表示がなってしまいました。
1 2 3 4 5となるにはどうしたらいいでしょうか?$posts = get_posts( $args ); $i = 0; foreach ( $posts as $post ): $i++; setup_postdata( $post ); // // ランキングされた投稿を表示 //
フォーラム: 使い方全般
返信が含まれるトピック: 記事がなかったら祖先タームから取得方法なるほど、
例えばある記事は、下記の様な階層構造のタームです。
一番下の階層のみにチェックが付いている場合は、
たしかに意図した表示になりました。
全部にチェックを入れると、階層構造でも全部対象となってしまうということでしょうか?美容整形・美容皮膚科コラム
-身体の整形・ダイエット・ボディメイキング
–豊胸・バストフォーラム: 使い方全般
返信が含まれるトピック: 記事がなかったら祖先タームから取得方法失礼いたしました。
タームです。例で言いますと、
https://call-to-beauty.com/column_category/bust/こちらのタームには記事が5つ以上あるので、
この中の記事詳細に行った時に表示されるランキングはこのタームの中のPV上位5つになるはず、
というイメージです。フォーラム: 使い方全般
返信が含まれるトピック: 記事がなかったら祖先タームから取得方法現在このようになっています
<ul class="list-ranking"> <?php $postid = get_the_ID(); // 現在の投稿のID $posttype = get_post_type(); // 現在の投稿の投稿タイプ $mytax = 'column_category'; // タクソノミー // 現在の投稿のターム(の配列) $ids = array(); $terms = get_the_terms( $postid, $mytax ); // タームのオブジェクトの配列 if ( ! is_wp_error( $terms ) && $terms ) { // 投稿にタームがついている時だけ foreach ( $terms as $term ) { $ids[] = $term->term_id; // タームIDの配列を作る } } $to_show = 5; // あと5つ表示したら終わり while ( $to_show > 0 ): if ( empty ( $ids ) ) { break; // 投稿にタームがないので表示終わり } // 同じタームを持つ投稿(現在の投稿を除く)を取得 $args = array( 'posts_per_page' => $to_show, 'post_type' => $posttype, 'meta_key' => 'views', 'orderby' => 'meta_value_num', 'tax_query' => array( array( 'taxonomy' => $mytax, 'terms' => $ids, 'include_children' => false, // タームの現階層のみ // 親タームの投稿の方がランキングが高くても子タームの方が優先される )), 'post__not_in' => array( $postid ) // 現在の投稿を除く ); $posts = get_posts( $args ); $i = 0; foreach ( $posts as $post ): $i++; setup_postdata( $post ); // // ランキングされた投稿を表示 // ?> <li class="media kanshu"> <!-- ランキング順位 --> <div class="rank"><?php echo $i; ?></div> <!-- サムネイル --> <div class="media-left"> <a href="<?php the_permalink() ?>"><?php the_post_thumbnail( 'thumb' ); ?></a> </div> <!-- 記事 --> <div class="media-body"> <a href="<?php the_permalink() ?>"><?php the_title(); ?></a> </div> </li> <?php endforeach; wp_reset_postdata(); $to_show -= count( $posts ); // 表示した分を減らす // 先祖タームを取得 // 現在の投稿に2つ以上タームがある場合、最初のタームに絞って先祖を取得 $ancestors = get_ancestors( reset( $ids ), $mytax, 'taxonomy' ); if ( count( $ancestors ) < 2 ) { break; // 親タームがないので表示終わり } $ids = array( $ancestors[1] ); // 親タームを次の対象にする endwhile; ?> <?php wp_reset_query(); ?> </ul>
フォーラム: 使い方全般
返信が含まれるトピック: 記事がなかったら祖先タームから取得方法ありがとうございます。
入れてみたのですが、変わらないですね。。
表示中の記事はランキングに出てこないようにはなっています。https://call-to-beauty.com/column_category/bust/
右カテゴリの人気ランキングがそうですが、
取得されるランキングはつねにカテゴリ全体の中のものになってます。。フォーラム: 使い方全般
返信が含まれるトピック: 記事がなかったら祖先タームから取得方法ありがとうございます。
しかし、自分の間違いを見つけることができません、、、
いきなり前回カテゴリから取得して来てるようです。。。><フォーラム: 使い方全般
返信が含まれるトピック: 記事がなかったら祖先タームから取得方法入れてみたのですが、
結果は一番親の階層からしか取得してきてないようです。https://call-to-beauty.com/column/c423/
もしかしてforeachの中の書き方が悪いのでしょうか???
<ul class="list-ranking"> <?php $postid = get_the_ID(); // 現在の投稿のID $posttype = get_post_type(); // 現在の投稿の投稿タイプ $mytax = 'column_category'; // タクソノミー // 現在の投稿のターム(の配列) $ids = wp_get_post_terms( $postid, $mytax, array( 'fields' => 'ids' ) ); $to_show = 5; // あと5つ表示したら終わり while ( $to_show > 0 ): if ( empty ( $ids ) ) { break; // 投稿にタームがないので表示終わり } // 同じタームを持つ投稿(現在の投稿を除く)を取得 $args = array( 'posts_per_page' => $to_show, 'post_type' => $posttype, 'meta_key' => 'views', 'orderby' => 'meta_value_num', 'tax_query' => array( array( 'taxonomy' => $mytax, 'terms' => $ids, 'include_children' => false, // タームの現階層のみ // 親タームの投稿の方がランキングが高くても子タームの方が優先される )), 'post__not_in' => array( $postid ) // 現在の投稿を除く ); $posts = get_posts( $args ); foreach ( $posts as $post ): setup_postdata( $post ); // // ランキングされた投稿を表示 // ?> <li class="media kanshu"> <!-- ランキング順位 --> <div class="rank"><?php echo $i;?></div> <!-- サムネイル --> <div class="media-left"> <a href="<?php the_permalink($posts->ID) ?>"><?php the_post_thumbnail($posts->ID,'thumb'); ?></a> </div> <!-- 記事 --> <div class="media-body"> <a href="<?php the_permalink($posts->ID) ?>"> <?php echo $post-> post_title;//mb_substr(strip_tags($post-> post_title),0,40).'...'; ?> </a> </div> </li> <?php endforeach; wp_reset_postdata(); $to_show -= count( $posts ); // 表示した分を減らす // 先祖タームを取得 // 現在の投稿に2つ以上タームがある場合、最初のタームに絞って先祖を取得 $ancestors = get_ancestors( reset( $ids ), $mytax, 'taxonomy' ); if ( count( $ancestors ) < 2 ) { break; // 親タームがないので表示終わり } $ids = array( $ancestors[1] ); // 親タームを次の対象にする endwhile; ?> <?php wp_reset_query(); ?> </ul>
フォーラム: 使い方全般
返信が含まれるトピック: タームの階層のループフォーラム: 使い方全般
返信が含まれるトピック: 記事がなかったら祖先タームから取得方法すいません、ソースが汚かったです。。。
まず、条件として5位までランキングを出したいです。
下記のソースでカスタム投稿の
記事詳細と同じタームのランキングは表示されます。
しかし、この場合ですとタームに3つしか記事がなかった場合、
3位までしかでません、
なので、その場合は一つ上位のタームからも拾って、
5位まで表示されるまで階層を登って行きたいです。<ul class="list-ranking"> <?php global $post; $ids = wp_get_object_terms( $post->ID, 'column_category', array( 'fields' => 'ids' ) ); $args = array( 'posts_per_page' => 5, 'post_type' => 'column', 'meta_key' => 'views', 'orderby' => 'meta_value_num', 'tax_query' => array( array( 'taxonomy' => 'column_category', 'terms' => $ids, 'include_children' => false, // ← 追加 'operator' => 'AND', // 'IN', 'NOT IN', 'AND' 等 )), ); $posts = get_posts($args); ?> <li class="media kanshu"> <!-- ランキング順位 --> <div class="rank"><?php echo $i;?></div> <!-- サムネイル --> <div class="media-left"> <a href="<?php the_permalink($posts->ID) ?>"><?php the_post_thumbnail($posts->ID,'thumb'); ?></a> </div> <!-- 記事 --> <div class="media-body"> <a href="<?php the_permalink($posts->ID) ?>"> <?php echo $post-> post_title;//mb_substr(strip_tags($post-> post_title),0,40).'...'; ?> </a> </div> </li> <?php endforeach; wp_reset_query();?> </ul>
フォーラム: 使い方全般
返信が含まれるトピック: 記事がなかったら祖先タームから取得方法ここまで書いてみたのですが、どうでしょうか??
<ul class="list-ranking"> <?php //現在のタームのidを取得 $term_id = get_queried_object()->term_id; //祖先タームのidを取得 $ancestors = get_ancestors( $term_id, 'my_taxonomy' ); //get_ancestors()は孫から親への順番で配列になるので、順番を入れ替える $reversed_ancestors = array_reverse($ancestors); global $post; $ids = wp_get_object_terms( $post->ID, 'column_category', array( 'fields' => 'ids' ) ); $args = array( 'posts_per_page' => 5, 'post_type' => 'column', 'meta_key' => 'views', 'orderby' => 'meta_value_num', /*'tax_query' => array( array( 'taxonomy' => 'column_category', 'terms' => $ids, 'include_children' => false, // ← 追加 'operator' => 'AND', // 'IN', 'NOT IN', 'AND' 等 ) ), */ ); $posts = get_posts($args); //print_r($posts); if( !empty( $myposts ) )://もし記事が空でなかったら $i = 0; foreach($posts as $post) : $i++; ?> <li class="media kanshu"> <!-- ランキング順位 --> <div class="rank"><?php echo $i;?></div> <!-- サムネイル --> <div class="media-left"> <a href="<?php the_permalink($posts->ID) ?>"><?php the_post_thumbnail($posts->ID,'thumb'); ?></a> </div> <!-- 記事 --> <div class="media-body"> <a href="<?php the_permalink($posts->ID) ?>"> <?php echo $post-> post_title;//mb_substr(strip_tags($post-> post_title),0,40).'...'; ?> </a> </div> <!--監修--> <?php $writers = get_posts(array( 'post_type' => 'doctor', 'meta_query' => array( array( 'key' => 'doctor_supervision', // name of custom field 'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234" 'compare' => 'LIKE' ) ) )); ?> <?php if( $writers ): ?> <?php foreach( $writers as $writer ): ?> <div id="relation"> <div class="media-left"> <a href="<?php echo get_the_permalink($writer->ID); ?>"> <?php echo get_the_post_thumbnail($writer->ID,'doc_thum' ); ?> </a> </div> <div class="article"> 医師監修 <span class="clinic"> <?php the_field('doctor_clinic', $writer->ID); ?> </span> <a href="<?php echo get_permalink( $writer->ID ); ?>"> <?php echo get_the_title( $writer->ID ); ?> </a> <?php the_field('keisho', $writer->ID); ?> </div> </div> <?php endforeach; wp_reset_query();?> <?php endif; ?> <!--//監修--> </li> <?php endforeach; wp_reset_query();?> <li>準備中です。</li> <?php endif; ?> <?php wp_reset_query(); ?> </ul>
フォーラム: 使い方全般
返信が含まれるトピック: 記事がなかったら祖先タームから取得方法フォーラム: 使い方全般
返信が含まれるトピック: AMP for WordPressで画像が出ない原因がわかりました。
function に書かれた非同期jquryの記述でした。
消したら表示されました。
ありがとうございます。フォーラム: 使い方全般
返信が含まれるトピック: AMP for WordPressで画像が出ない