wordpressでサイトを作っています。
そこで、カスタム投稿にタグを入れてそのタグをサイドバーに表示させたいのですが、うまくいきません。
実装方法
function.phpに
php
1register_post_type( 2'hogehoge', 3 array( 4 'label' => 'ホゲホゲ', 5 'hierarchical' => false, 6 'public' => true, 7 'query_var' => false, 8 'menu_position' => 5, 9 'has_archive' => true, 10 'supports' => array('title','editor', 'thumbnail') 11 ) 12); 13 14 /* カスタムタクソノミーを定義 */ 15 register_taxonomy( 16 'hogehoge_cat', 17 'hogehoge', 18 array( 19 'label' => 'カテゴリー', 20 'hierarchical' => true, 21 'rewrite' => array('slug' => 'motedate') 22 ) 23 ); 24 25 register_taxonomy( 26 'hogehoge_tag', 27 'hogehoge', 28 array( 29 'hierarchical' => false, 30 'label' => 'タグ', 31 'public' => true, 32 'show_ui' => true 33 ) 34 ); 35/* カスタムタクソノミーを定義ここまで */ 36 37 38 /* 管理画面一覧にカテゴリを表示 */ 39 function manage_hogehoge_columns($columns) { 40 $columns['hogehoge_category'] = "カテゴリー"; 41 return $columns; 42 } 43 function add_hogehoge_column($column_name, $post_id){ 44 if( $column_name == 'hogehoge_category' ) { 45 //カテゴリー名取得 46 if( 'hogehoge_category' == $column_name ) { 47 $hogehoge_category = get_the_term_list($post_id, 'hogehoge_cat', '', ', ', '' ); 48 } 49 //該当カテゴリーがない場合「なし」を表示 50 if ( isset($hogehoge_category) && $hogehoge_category ) { 51 echo $hogehoge_category; 52 } else { 53 echo __('None'); 54 } 55 } 56 } 57 add_filter('manage_edit-hogehoge_columns', 'manage_hogehoge_columns'); 58 add_action('manage_posts_custom_column', 'add_hogehoge_column', 10, 2); 59 /* 管理画面一覧にカテゴリを表示ここまで */ 60add_action('init', 'myposttype_rewrite'); 61function myposttype_rewrite() { 62 global $wp_rewrite; 63 $queryarg = 'post_type=hogehoge&p='; 64 $wp_rewrite->add_rewrite_tag('%hogehoge_id%', '([^/]+)',$queryarg); 65 $wp_rewrite->add_permastruct('hogehoge', '/hogehoge/%hogehoge_id%.html', false); 66} 67
と書いて
sidebar.phpに
php
1<?php $term_list = get_the_term_list( $post->ID, 'hogehoge_tag', '<ul><li>','</li><li>','</li></ul>'); ?> 2<?php if ( $term_list ): ?> 3 <?php echo $term_list; ?> 4<?php endif; ?>
と書きましたがタグが表示されません
どなたか、解決策をご存知の方がいましたら教えてください!
WordPressのバージョンは 4.3.1です。
よろしくお願いします!
あなたの回答
tips
プレビュー