wordpress在have_posts循环中获取自定义帖子类型类别链接

时间:2015-09-25 07:42:25

标签: php wordpress

如何在while has_posts循环中获取自定义帖子类型类别链接。这是我用来获取类别名称的代码:

    <?php query_posts(array('post_type'=>'portfolio'));?>
       <?php while ( have_posts() ) : the_post();?>
           <?php $feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );?>
    <div class="col-md-3 col-md-3-portfolio">
        <div class="portfoliobox">
            <img src="<?php echo $feat_image;?>" />
               <div class="portfolio-title-block">
                <h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
       <?php
            $terms = get_the_terms($post->ID, 'portfolio-category' );
            if ($terms && ! is_wp_error($terms)) :
            $tslugs_arr = array();
            foreach ($terms as $term) {
                $tslugs_arr[] = $term->slug;
            }
            $terms_slug_str = join( " ", $tslugs_arr);
            endif;
            $idObj = get_category_by_slug('portfolio-category'); 
            $id = $idObj->term_id;
       ?>
                <p><a href="<?php get_category_link( $id ); ?> "><?php echo $terms_slug_str;?></a></p>
               </div>
           </div>
       </div>
       <?php endwhile;?>

谢谢你。

0 个答案:

没有答案