ホテル・結婚式場などのホームページがつくれるエレガントなデザインのテンプレート「CANON」

ワードプレステーマ別

TCDテーマREHUB:日本地図に孫カテゴリーを表示させる方法

WordPressテーマ「NULL」

TCD LABOはWordPressテーマ「NULL」を使用して作られています。

ダウンロード

Q.日本地図コンテンツに孫カテゴリーを表示させたいです。

テーマの仕様変更(v3.0→3.1)に伴って、日本地図コンテンツにはレビューカテゴリーの2階層目までしか表示されない仕様となっております。
この仕様を修正して、孫カテゴリーも表示させるカスタマイズ方法をご紹介します。

テーマファイルを編集します。
編集するファイル: functions/japan-map/class-tcd-japan-map.php
編集する箇所:129行目 

$child_terms = get_terms( array(
 'taxonomy' => 'review_category',
 'hide_empty' => false,
 'parent' => $term_id
 ) );

if( is_wp_error( $child_terms ) || empty( $child_terms ) ){
  $child_terms = array( $term );
}

foreach( $child_terms as $key => $child_term ){
 $is_empty = $child_term->count == 0 ? 'is-empty' : '';
  echo '<a class="p-jmap-a-list__terms-link ' . $is_empty . '" href="' . esc_url( get_term_link( $child_term ) ) . '">' . esc_html( $child_term->name ) . '</a>';
}

↓↓↓

$child_term_ids = get_terms(array(
  'taxonomy' => 'review_category',
  'child_of'   => $term_id,
  'orderby' => 'none',
  'hide_empty' => false
));
  if( is_wp_error( $term ) || empty( $child_term_ids ) ){
    $child_term_ids = array( $term_id );
  }

foreach( $child_term_ids as $key => $term_id ){
  $term = get_term( $term_id, 'review_category' );
    if( ! is_wp_error( $term ) && ! empty( $term ) ){
     echo '<a class="p-jmap-a-list__terms-link" href="' . esc_url( get_term_link( $term ) ) . '">' . esc_html( $term->name ) . '</a>';
    }
 }

編集するファイル: functions/japan-map/class-tcd-japan-map.php
編集する箇所:176行目 

$child_terms = get_terms( array(
 'taxonomy' => 'review_category',
 'hide_empty' => false,
 'parent' => $term_id
) );

if( is_wp_error( $child_terms ) || empty( $child_terms ) ){
 $child_terms = array( $term );
}

foreach( $child_terms as $key => $child_term ){
  if( $key != 0 ){
    echo '<span class="p-jmap-b-list__terms-sep"></span>';
  }
  $is_empty = $child_term->count == 0 ? 'is-empty' : '';
  echo '<a class="p-jmap-b-list__terms-link ' . $is_empty . '" href="' . esc_url( get_term_link( $child_term ) ) . '">' . esc_html( $child_term->name ) . '</a>';
}

↓↓↓

$child_term_ids = get_terms(array(
  'taxonomy' => 'review_category',
  'child_of'   => $term_id,
  'orderby' => 'none',
  'hide_empty' => false
));
  if( is_wp_error( $term ) || empty( $child_term_ids ) ){
    $child_term_ids = array( $term_id );
  }

foreach( $child_term_ids as $key => $term_id ){
  $term = get_term( $term_id, 'review_category' );
    if( ! is_wp_error( $term ) && ! empty( $term ) ){
     echo '<a class="p-jmap-a-list__terms-link" href="' . esc_url( get_term_link( $term ) ) . '">' . esc_html( $term->name ) . '</a>';
    }
 }

編集するファイル: functions/japan-map/class-tcd-japan-map.php
編集する箇所:223行目 

$child_terms = get_terms( array(
  'taxonomy' => 'review_category',
  'hide_empty' => false,
  'parent' => $term_id
) );

if( is_wp_error( $child_terms ) || empty( $child_terms ) ){
  $class = '';
  $child_terms = array( $term );
}

↓↓↓

$child_term_ids = get_terms(array(
  'taxonomy' => 'review_category',
  'child_of'   => $term_id,
  'orderby' => 'none',
  'hide_empty' => false
));
 if( is_wp_error( $term ) || empty( $child_term_ids ) ){
   $class = '';
   $child_term_ids = array( $term_id );
}

編集するファイル: functions/japan-map/class-tcd-japan-map.php
編集する箇所:249行目 

foreach( $child_terms as $key => $child_term ){
  $is_empty = $child_term->count == 0 ? 'is-empty' : '';
  echo '<div class="p-jmap-sp__terms-item">';
  echo '<a class="p-jmap-sp__terms-link ' . $is_empty . '" href="' . esc_url( get_term_link( $child_term ) ) . '">' . esc_html( $child_term->name ) . '</a>';
  echo '</div>';
}

↓↓↓

foreach( $child_term_ids as $key => $term_id ){
  $term = get_term( $term_id, 'review_category' );
  if( ! is_wp_error( $term ) && ! empty( $term ) ){
  echo '<div class="p-jmap-sp__terms-item">';
  echo '<a class="p-jmap-sp__terms-link" href="' . esc_url( get_term_link( $term ) ) . '">' . esc_html( $term->name ) . '</a>';
  echo '</div>';
 }
}

▼設定後イメージ

備考

  • 上記のカスタマイズ対応後、孫カテゴリーが該当の子カテゴリーの下に配置されない場合は、「Category Order and Taxonomy Terms Order」といったプラグインを使用し、都道府県の配下で、地域カテゴリーの順番を並び替えてください。
  • 地域が多くなりすぎると、日本地図や他の地域のリンクと重なってしまう可能性があります。カスタムCSSで適宜調節してください。※数値はお好みで変更してください。
    /*タイプA*/
    .p-jmap-a-list__terms-link{
      width: 60px;
      height: 28px;
    }
    /*タイプB*/
    .p-jmap-b-list__terms{
      gap: 4px;
    }
    
  • 日本地図」機能を使用するには、テーマをメジャーアップデート「Ver2.0以上に更新してご利用ください。

関連記事

この記事は役に立ちましたか?

もし参考になりましたら、下のボタンで教えてください。
今後の記事作成の参考とさせて頂きます!

同じテーマのカスタマイズ記事