2013-04-18 24 views
0

在for循環中查看所有帖子如何將帖子的所有標籤附加爲div類的一部分?如何將類添加標籤作爲類

   <?php 
     $page_name = $wp_query->post->post_name; 
     query_posts('category_name='. $page_name .'&posts_per_page=-1&orderby=date&order=DESC'); 
     ?> 
      <?php if (have_posts()) : while (have_posts()) : the_post(); ?> 
       <div class="galleryItem "> 
        <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> 
        <div class="titlePlate"> 
         <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"> <?php the_title(); ?></a></h3> 
        </div><!--END titlePlate--> 
       </div><!--END galleryItem-->   

      <?php endwhile; else: ?> 

       <p>Sorry, no posts matched your criteria.</p> 

      <?php endif; ?><?php wp_reset_query(); ?> 

回答

0

您可以使用下面的代碼打印後的所有標籤:

<?php 
$postid = get_the_ID(); 
$tags = wp_get_post_tags($postid); 

foreach ($tags as $tag) { 
echo $tag->name . " "; //put a space to seperate every tag. 
} 
?> 

這些代碼會顯示該信息的所有標籤,然後你就可以將其插入類屬性確切的分區,你需要的。

相關問題