前提・実現したいこと
お知らせページは通常の投稿で行い、ブログ投稿を別でカスタム投稿で実装していたのですが、カテゴリー名だけ表示されなくて困っています。
お手数おかけしますが、ご回答よろしくお願いいたします。(>_<)
該当のソースコード
php
1 2// カスタム投稿タイプ「ブログ」を追加する 3 4 5add_action( 'init', 'create_post_type_blog' ); 6function create_post_type_blog() { 7register_post_type( 'blog', //カスタム投稿タイプ名 8array( 9'labels' => array( 10'name' => __( 'ブログ' ), 11'all_items' => __( 'ブログ一覧' ), 12 13), 14'public' => true, 15'has_archive' => true, //アーカイブページを持つ 16'menu_position' =>5, //管理画面のメニュー順位 17'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'custom-fields' ,'comments' ), 18) 19); 20/* カテゴリーの設定 */ 21register_taxonomy( 22'blog_category', //カテゴリーの名前 23'blog', //使うカスタム投稿タイプ名 24array( 25'hierarchical' => true, //trueで親子関係使用 26'update_count_callback' => '_update_post_term_count', 27'label' => 'カテゴリー', 28'singular_label' => 'カテゴリー', 29'public' => true, 30'show_ui' => true 31) 32); 33/* タグを設定 */ 34register_taxonomy( 35'blog_tag', //タグの名前 36'blog', //使うカスタム投稿タイプ名 37array( 38'hierarchical' => false, 39'update_count_callback' => '_update_post_term_count', 40'label' => 'タグ', 41'singular_label' => 'タグ', 42'public' => true, 43'show_ui' => true 44) 45); 46} 47
php
1 2<ul class="col col4 col_sp_full"> 3 <?php 4 $args = array( 5 'post_type' => ‘blog’, 6 'posts_per_page' => 4 7 ); 8 $query = new WP_Query( $args ); 9 ?> 10 11 <?php if ( $query->have_posts() ) : ?> 12 <?php while ( $query->have_posts() ) : $query->the_post();?> 13 14 <li> 15 <a href="<?php the_permalink(); ?>" class="ddm-block"> 16 <?php the_post_thumbnail(); ?> 17 <div class="home-strength-list-inner"> 18 <div class="tag"> 19 <span> 20 <?php 21 global $post; 22 $terms = get_the_terms($post->ID, 'blog_category'); 23 ?> 24 </span> 25 </div> 26 <h4><?php the_title(); ?></h4> 27 <p> 28 <?php echo mb_substr($post->post_content, 0, 60).'…'; ?> 29 </p> 30 <div class="date-text"><?php the_time( 'Y.m.d' ); ?></div> 31 </div><!--/.home-strength-list-inner--> 32 </a> 33 </li> 34 35 <?php endwhile; ?> 36 <?php endif; wp_reset_postdata(); ?> 37 38 </ul> 39
試したこと
php
1<div class="tag"> 2 <span> 3 <?php 4 $terms = get_the_terms($post->ID, 'blog'); 5 var_dump($terms); 6 ?> 7 </span> 8</div>
を追加したら、
このようなエラーが出ました。
回答3件
あなたの回答
tips
プレビュー