2014-12-03 18 views
11

Bu sitenin WordPress'inde kurulu olan F9 Properties yönetiminden sorumluyum. Ana sayfada öne çıkan özellikler bölümü var. "Satış veya For Lease" gibi iki farklı "Durum" ile bir mülkün listelendiğini fark ettiyseniz, mülkün karuselde iki kez göründüğünü fark ettim. Aşağıda, öne çıkan özellikleri listelemenin kodu yer almaktadır. "Kiralık" Statülü. herkes?İleti Çoğaltmalarını Önleme

<?php 
/* Featured Properties Query Arguments */ 
$featured_properties_args = array(
'post_type' => 'property', 
'posts_per_page' => 100, 
'meta_query' => array(
    array(
     'key' => 'REAL_HOMES_featured', 
     'value' => 1, 
     'compare' => '=', 
     'type' => 'NUMERIC' 
    ) 
) 
); 

$featured_properties_query = new WP_Query($featured_properties_args); 

if ($featured_properties_query->have_posts()) : 
?> 
<section class="featured-properties-carousel clearfix"> 
    <?php 
    $featured_prop_title = get_option('theme_featured_prop_title'); 
    $featured_prop_text = get_option('theme_featured_prop_text'); 

    if(!empty($featured_prop_title)){ 
     ?> 
     <div class="narrative"> 
      <h3><?php echo $featured_prop_title; ?></h3> 
      <?php 
      if(!empty($featured_prop_text)){ 
       ?><p><?php echo $featured_prop_text; ?></p><?php 
      } 
      ?> 

     </div> 
     <?php 
    } 

    ?> 

     <div class="carousel es-carousel-wrapper"> 
     <div class="es-carousel"> 
      <ul class="clearfix"> 
       <?php 
       while ($featured_properties_query->have_posts()) : 
        $featured_properties_query->the_post(); 
        ?> 

        <?php 
       $status_terms = get_the_terms($post->ID,"property-status"); 
       if(!empty($status_terms)){ 
        foreach($status_terms as $status_term){ 

         if($status_term->name=="Leased"){}else{ 

          ?> 
          <li> 
         <figure> 
          <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> 
           <?php 
           the_post_thumbnail('property-thumb-image',array(
            'alt' => get_the_title($post->ID), 
            'title' => get_the_title($post->ID) 
           )); 
           ?> 
          </a> 
         </figure> 
         <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4> 
         <p><?php framework_excerpt(8); ?> <a href="<?php the_permalink() ?>"> <?php _e('Know More','framework'); ?> </a> </p> 
         <span class="price"><?php property_price(); ?></span> 

        </li> 
          <? 
         } 


        } 
       } 
       ?> 

        <?php 
       endwhile; 
       wp_reset_query(); 
       ?> 
      </ul> 
     </div> 
    </div> 
+0

Eğer '$ featured_properties_query' için' WP_Query' kısmını paylaşır:

Sonra atlıkarınca için basitleştirilmiş olurdu? – birgire

cevap

4

Ben Ayarlarınızı yanlış anlama olabilir, ama merak ediyorum Neden terimlerin üzerinden geçiyorsun?

ben yerine WP_Query() parçası (umarım bunu paylaşabilirsiniz) içindeleased terimi hariç düşünmelisin.

<div class="carousel es-carousel-wrapper"> 
    <div class="es-carousel"> 
     <ul class="clearfix"> 
     <?php while ($featured_properties_query->have_posts()) : $featured_properties_query->the_post(); ?> 
      <li><!-- YOUR POST ITEM HERE --></li> 
     <?php endwhile; ?> 
     </ul> 
    </div> 
</div> 
0

Sen bir diziye sonrası kimlik ekleyebilir olursa olsun kaç farklı özellik durumu beni gönderim başına yalnızca bir özellik listelemek için kod parçasını ekleyin yardım edebilir her zaman bir yineleme oluşur ve yayın zaten hale getirilmesi durumunda diziyi kontrol edin:

$shown = array(); // new array 
while ($featured_properties_query->have_posts()) : 
    $featured_properties_query->the_post(); 
    $status_terms = get_the_terms($post->ID, 'property-status'); 
    if(! empty($status_terms)){ 
     foreach($status_terms as $status_term){ 
      if($status_term->name == "Leased" || in_array($post->ID, $shown){ 
       continue; // post has term "Leased" or already rendered, skip 
      } 
      $shown[] = $post->ID; // add post ID to array 
     ?> 
      <!-- HTML here --> 
     <?php 
     } 
    } 
endwhile; 
İlgili konular