サポート » テーマ » Lightningテーマの投稿一覧にタグを表示したい

  • 解決済 landscape2019

    (@landscape2019)


    Lightningテーマの投稿一覧にカテゴリーは表示されますが、タグは表示されません。
    カスタマイズでタグを表示する方法がありましたら、お教えください。
    よろしくお願いいたします。

    ヘルプの必要なページ: [リンクを見るにはログイン]

6件の返信を表示中 - 1 - 6件目 (全6件中)
  • DRILL LANCER

    (@rickaddison7634)

    カテゴリー名を複数表示する

    上記サイトを参考にしつつ、下記の部分のbreak;を消去すると関連付けられた全ての分類(カテゴリ、タグ、product 以外のカスタム分類)を表示することができると思います。

    // get $taxonomy name
    // $taxonomy   = key( $taxonomies );
    // To avoid WooCommerce default tax
    foreach ( $taxonomies as $key => $value ) {
    	if ( $key != 'product_type' ) {
    		$taxonomy = $key;
    		break;
    	}
    }

    【参考になりそうなサイト】

    • この返信は4年、 1ヶ月前にDRILL LANCERが編集しました。
    トピック投稿者 landscape2019

    (@landscape2019)

    DRILL LANCER様

    回答ありがとうございます。
    「break;」を消去したところ、タグが表示される代わりにカテゴリが消えてしまいました。
    よろしくお願いいたします。

    DRILL LANCER

    (@rickaddison7634)

    if ( $taxonomies ) :endif;の部分を下記のように書き換えるとどうなりますか?

    if ( $taxonomies ) :
    	// get $taxonomy name
    	// $taxonomy   = key( $taxonomies );
    	// To avoid WooCommerce default tax
    	foreach ( $taxonomies as $key => $value ) {
    		if ( $key != 'product_type' ) {
    			$taxonomy = $key;
    		}
    		$terms = get_the_terms( get_the_ID(), $taxonomy );
    
    		foreach ( $terms as $key => $term ) {
    			$term_url   = esc_url( get_term_link( $term->term_id, $taxonomy ) );
    			$term_name  = esc_html( $term->name );
    			$term_color = '';
    			if ( class_exists( 'Vk_term_color' ) ) {
    					$term_color = Vk_term_color::get_term_color( $term->term_id );
    					$term_color = ( $term_color ) ? ' style="background-color:' . $term_color . ';border:none;"' : '';
    			}
    			echo '<span class="entry-meta_items entry-meta_items_term"><a href="' . $term_url . '" class="btn btn-xs btn-primary"' . $term_color . '>' . $term_name . '</a></span>';
    
    		}
    	}
    
    endif;
    • この返信は4年、 1ヶ月前にDRILL LANCERが編集しました。
    トピック投稿者 landscape2019

    (@landscape2019)

    カテゴリとタグを両方表示することができました。
    ありがとうございます。
    タグをカテゴリの下の行、または抜粋文の下にできませんでしょうか。
    よろしくお願いいたします。

    http://www2.office-landscape.co.jp/works

    DRILL LANCER

    (@rickaddison7634)

    タグをカテゴリの下の行、または抜粋文の下にできませんでしょうか。
    よろしくお願いいたします。

    抜粋文の下はファイルが違うのでここまで来た段階から変えるのはさすがに面倒です。
    カテゴリの下の行に配置する方法なら前回の部分を下記のように変更し

    if ( $taxonomies ) :
    	// get $taxonomy name
    	// $taxonomy   = key( $taxonomies );
    	// To avoid WooCommerce default tax
    	foreach ( $taxonomies as $key => $value ) {
    		if ( $key != 'product_type' ) {
    			$taxonomy = $key;
    		}
    		
    		$terms = get_the_terms( get_the_ID(), $taxonomy );
    		echo '<div class="entry-taxonomy">';
    		foreach ( $terms as $key => $term ) {
    			$term_url   = esc_url( get_term_link( $term->term_id, $taxonomy ) );
    			$term_name  = esc_html( $term->name );
    			$term_color = '';
    			if ( class_exists( 'Vk_term_color' ) ) {
    					$term_color = Vk_term_color::get_term_color( $term->term_id );
    					$term_color = ( $term_color ) ? ' style="background-color:' . $term_color . ';border:none;"' : '';
    			}
    			echo '<span class="entry-meta_items entry-meta_items_term"><a href="' . $term_url . '" class="btn btn-xs btn-primary"' . $term_color . '>' . $term_name . '</a></span>';
    
    		}
    		echo '</div>';
    	}
    endif;

    子テーマの style.css に下記を追加すれば行けると思います。

    .entry-taxonomy {
    	display: block;
    }
    トピック投稿者 landscape2019

    (@landscape2019)

    タグをカテゴリーの下に表示できました。
    ありがとうございます。

6件の返信を表示中 - 1 - 6件目 (全6件中)
  • トピック「Lightningテーマの投稿一覧にタグを表示したい」には新たに返信することはできません。