2013-12-09 39 views
0

如果您想將帖子類別列爲鏈接,請將其覆蓋。我有一個問題,我想要一個列表類別空間分隔作爲div的data-id屬性的值。Wordpress列出帖子類別作爲標籤屬性

這是我的電流環路的樣子:

<?php while (have_posts()) : the_post(); ?> 
    <?php $post_id = the_ID(); $post_categories = wp_get_post_categories($post_id); ?> 
     <div class="box" data-id=" <?php foreach($post_categories as $c){ echo $c; } ?>  "> 
      <?php the_post_thumbnail(array(200,200)); ?> 
      <div class="caption"> 
       <div class="blur"></div> 
       <div class="caption-text"> 
        <h3><a href="<?php esc_url(the_permalink()); ?>" title="Permalink to <?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></h3> 
        <p><?php the_excerpt(); ?></p> 
       </div> 
      </div> 
     </div> 
     <?php endwhile; ?> 

不幸的是,結果看起來像Loop visual output

我想這是一個沒有腦子了一些你,但我不能讓對的。感謝您看看它!

回答

0

使用get_the_ID()返回ID:

wp_get_post_categories(get_the_ID()); 
+0

非常感謝DIGGY,就像一個魅力! – user1106402

相關問題