2017-11-17 1 views
0

Ich habe eine Schleife in meinem index.php
und ich möchte Kategorie-ID hinzufügen schreiben Klasse
i viele Code try'd aber ich did't den richtigen Code
hier bekam ist Was ich habe:wie man Post Kategorie ID

<?php if (have_posts()):?> 
    <?php $catID = get_the_category('id');?> 
    <ul> 
     <?php while(have_posts()): the_post();?> 
     <li class="cat<?php get_the_category($post->ID);?>"> 
      <a href="<?php the_permalink();?>"> 
       <?php $src= wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(250,220), false, ''); $thumbnailSrc = $src[0]; ?> 
       <img class="thumbnail" src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo $thumbnailSrc;?>&w=250&h=220&zc=1q=100" alt=""> 
       <span class="hover"></span> 
       <h2><?php the_title();?></h2> 
       <h3>توضیحات بیشتر<?php echo $catID; ?></h3> 
      </a> 
     </li> 
     <?php endwhile;?> 
    </ul> 
<?php endif;?> 

Antwort

-2

Speichern Sie die $ _POST zu einem zusätzlichen Array, dann können Sie es ändern.

0

Da Sie in einer Schleife sind, sollten Sie the_category() anstelle von get_the_category()

<?php if (have_posts()):?> 

     <ul> 
      <?php while(have_posts()): the_post();?> 
      <li class="cat<?php the_category();?>"> 
       <a href="<?php the_permalink();?>"> 
        <?php $src= wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), array(250,220), false, ''); $thumbnailSrc = $src[0]; ?> 
        <img class="thumbnail" src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php echo $thumbnailSrc;?>&w=250&h=220&zc=1q=100" alt=""> 
        <span class="hover"></span> 
        <h2><?php the_title();?></h2> 
        <h3>توضیحات بیشتر<?php echo $catID; ?></h3> 
       </a> 
      </li> 
      <?php endwhile;?> 
     </ul> 
    <?php endif;?> 
Verwandte Themen