0
votes

The code below is for my single.php. The php if ( have_posts() ) calls the standard wordpress feature image and the function_exists('dfi_get_featured_images') sections grabs slider images that are wrapped in nivo-slider styling.

The php if ( have_posts() ) loop is breaking the script. I tried to include it in an if else statement to only show the wordpress featured image if there are no slide images in the post if($featuredImages!=NULL).

Any help on the coding would be great.

Thanks...Lee

<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 ?>

  }

?>
1

1 Answers

0
votes
<?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          

?>  

A few things to note:

You don't have to keep opening and closing your php at the beginning and ending of every line. It makes the code cluttered much harder to read.

Think about what you're actually trying to do. You don't want to delete the featured image if there is a slider instead -- you want to show the slider instead of the featured image (at least, that's what it sounds like to me). Here is the thought process behind this code:

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
}

So you will first check for the plugin, then the presence of plugin images, and if either of those comes back negative you will display the thumbnail image.