2014-02-14 21 views
0

下面的代碼是爲我的single.php。 php if(have_posts())調用標準wordpress特徵圖像,而function_exists('dfi_get_featured_images')部分抓取包含在nivo-slider樣式中的滑塊圖像。刪除精選圖片如果Slider存在Single.php

php if(have_posts())循環正在破壞腳本。我嘗試將它包含在if else語句中,以便僅在if($ featuredImages!= NULL)中沒有幻燈片圖像時顯示WordPress特色圖像。

對編碼的任何幫助都會很棒。

謝謝...李

<div id="featured" class="row-fluid"> 
<?php 
if (function_exists('dfi_get_featured_images')) {    
    $featuredImages = dfi_get_featured_images();    
if(!is_null($featuredImages)){ 
echo "<div class='slider-wrapper theme-default'>"; 
     echo "<div class='entry-thumbnail nivoSlider' style='width: 1170px;'>"; 
     foreach($featuredImages as $images) { 
      echo "<a href='" . get_permalink() . "' title = '" .  dfi_get_image_alt_by_id($images['attachment_id']) . "'>"; 
      echo "<img src = '" . $images['thumb'] . "' />"; 
      echo "</a>";           
     } 
     echo "</div>"; 
     echo "</div>"; 
    } 
} 
if($featuredImages!=NULL) 
{ 

} 
else 
{ 
<?php if (have_posts()) { ?> 
      <?php while (have_posts()) { ?> 
       <?php the_post(); ?> 
       <?php if ('' != get_the_post_thumbnail()) { ?> 
        <?php the_post_thumbnail('full'); ?> 
       <?php } // end if ?> 
      <?php } // end while ?> 
     <?php } // end have_posts ?> 

    } 

?> 

回答

0
<?php 
    if (have_posts()) { 
     while (have_posts()) { 
      the_post(); 

      if (function_exists('dfi_get_featured_images')) { // If the featured images function exists   
       $featuredImages = dfi_get_featured_images(); // Get those featured slider images   
       if(!is_null($featuredImages)) { //If there are featured slider images to get, then: 

        echo "<div class='slider-wrapper theme-default'>"; 
        echo "<div class='entry-thumbnail nivoSlider' style='width: 1170px;'>"; 
        foreach($featuredImages as $images) { 
         echo "<a href='" . get_permalink() . "' title = '" . dfi_get_image_alt_by_id($images['attachment_id']) . "'>"; 
         echo "<img src = '" . $images['thumb'] . "' />"; 
         echo "</a>";           
        } 
        echo "</div>"; 
        echo "</div>"; 

       } else { 
        the_post_thumbnail('full'); 
       } 
      } else if (has_post_thumbnail()) { //If there are no featured images to get, but there is a thumbnail 
       the_post_thumbnail('full'); 
      } // end else if 
     } // end while 
    } // end hav_posts   

?> 

有幾件事情需要注意:

你不必保持開放,並在開始關閉你的PHP和每一個結束線。它使代碼更加難以閱讀。

想想你實際上想要做什麼。如果存在滑塊,則不想刪除特色圖像 - 您想要顯示滑塊而不是特色圖像(至少,這是我聽起來的樣子)。下面是該代碼背後的思維過程:

if (has function check if dfi images is registered) { 
    check and see if there are andy dfi images 
    if there are dfi images { 
     loop through them and display them 
    } else if dfi images is registered but there are no dfi images { 
     display the thumbnail 
    } 
} else, dfi images must not be registered { 
    display the thumbnail 
} 

所以,你會首先檢查該插件,那麼插件圖像的存在,如果任那些回來消極,你會顯示縮略圖。

+0

工作完美!謝謝Ceili。 – king136