2016-04-11 27 views
1

Özel bir gönderi türü için tüm gönderilerin arasında dolaşmak istiyorum, ancak döngü yaparken belirli bir terimle etiketlenen yayınlara bir sınıf ekleyin.WordPress - Belirli bir dönem döngüsüne özel sınıflar ekleme

Şu anda aşağıdaki işleve sahibim, ancak bu, yalnızca belirli bir terimle gönderileri kapsıyor ve kenarlarındaki tüm gönderileri değil. Yukarıdaki

ile

/** 
* Get posts of particular termID 
*/ 

function post_type_tax_query($post_type=null, $taxonomy=null, $term_id=null){ 

    $args = array(
     'posts_per_page' => -1, 
     'post_type'  => $post_type, 
     'orderby'   => 'post_date', 
     'order'   => 'DESC', 
     'tax_query' => array(
      array(
       'taxonomy' => $taxonomy, 
       'field' => 'id', 
       'terms' => $term_id 
      ) 
     ) 
    ); 

    $the_query = new \WP_Query($args); 
    $queryitems = $the_query->get_posts(); 

    return $queryitems; 

} 

Benim akım döngüsü

  $projects_posts = post_type_tax_query('projects', 'locked', '5'); 
       if($projects_posts){ ?> 
        <ul class="full-width projects-grid grid list-style-none"> 
        <?php $counter = 1; ?> 
        <?php foreach ($projects_posts as $project): 
          $project_title = get_field('project_title', $project->ID); // get all the rows 
          $project_image_thumbnail = get_field('project_thumbnail_image', $project->ID); ?> 
          <li class="animation-element bounce-up delay-motion-<?php echo $counter; ?> col-lg-4 col-xs-12 col-sm-6"> 
           <a href="<?php echo the_permalink($project->ID); ?>" target="_blank"> 
            <figure class="effect-milo"> 
             <img src="<?php echo $project_image_thumbnail; ?>"/> 
             <h4><?= $project_title; ?></h4> 
            </figure> 
           </a> 
          </li> 
        <?php $counter++; ?> 
        <?php endforeach; ?> 
        </ul> 
      <?php } ?> 

Sadece Ben tüm yayınlar yoluyla döngüler sağlamak için yukarıda düzenleyebilirsiniz ancak terim 5. This belirli mesajların için bir sınıf uygular nasıl merak stil amaçlıdır.

sayesinde

DIM3NSION Doğru ama belki böyle bir şey soruyu anlamak bilmiyorum

cevap

1

foreach döngü içinde Gönderi belli bir kategoriye ait. öyleyse, sonra sınıfı veya almak istediğiniz eylemi ekleyin.

$special_class=''; 
if(has_term($term_id', $taxonomy, $post_id)) { 
    # in your case term_id = 5 
    $special_class='CLASS_YOU_WANT_ADD'; 
    # Print $special_class into the li class 
    # OR Whatever you want to do 
} 
0

: Eğer kontrol etmek has_term() işlevini kullanabilirsiniz

<?php if ($term === 'theTerm') :?> 
    <div class="classfortheterm"></div> 
<?php endif ?> 
İlgili konular