2017-01-04 10 views
0

私はワードプレスの投稿タイプの投稿のリストを表示したいのですが、投稿にリンクされているタクソノミの用語を表示する方法がわかりません。 マイコード:タクソノミの投稿一覧

<ul class="list-group"> 
    <?php 
    $args = array(
     'post_type' => 'faq', 
     'post_status' => 'publish', 
     'orderby'   => 'date', 
     'order'   => 'DESC', 
     'posts_per_page' => 5, 

    ) 
    ;$myposts = get_posts($args); 
    foreach ($myposts as $post) : setup_postdata($post); ?> 
     <li class="list-group-item"> 
     <span class="label label-default">xxxxx taxonomy xxxxxx</span> 
    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 
    </li> 
    <?php endforeach; 
    wp_reset_postdata();?> 
    </ul> 

お願いします。

答えて

0
<?php query_posts(array('post_type'=>'faq', 'posts_per_page'=>5, 'order' => 'DESC',)); ?> 
    <?php if(have_posts()) { while(have_posts()) { the_post();?> 
    <div class="col-md-6 col-sm-6"> 
     <?php if (has_post_thumbnail()) {?> 
      <div class="blog_image"> 
       <?php the_post_thumbnail('full'); ?> 
      </div> 
     <?php } else{ ?> 
     <?php }?> 
     <div class="entry-content"> 
      <h3 class="blog-title"> 
       <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> 
      </h3> 
      <span class="post-date"><?php echo get_the_date('d. M Y'); ?></span> 
      <p><?php echo wp_trim_words(get_the_content(), 50, ' (...)');?></p> 
     </div> 
    </div> 
<?php } 
    } 
    wp_reset_query(); 
?> 

for image display <?php the_post_thumbnail('full'); ?> 
for title display <?php the_title_attribute(); ?> for title display 
for content display <?php the_content();?> 

あなたは

+0

をしたいと変更HTMLありがとうございましたが、私は分類名が表示されません。それは私の質問と問題です。私はタノノミーの名前を表示したいと思います。 – Sam

0
<?php 
/* FIRST 
* Note: This function only returns results from the default “category” taxonomy. For custom taxonomies use get_the_terms(). 
*/ 
$categories = get_the_terms($post->ID, 'taxonomy'); 
// now you can view your category in array: 
// using var_dump($categories); 
// or you can take all with foreach: 
foreach($categories as $category) { 
    echo $category->term_id . ', ' . $category->slug . ', ' . $category->name . '<br />'; 
} 
関連する問題