0

以下のコードは、私の single.php 用です。PHP の if ( have_posts() ) は標準のワードプレス機能イメージを呼び出し、 function_exists('dfi_get_featured_images') セクションは nivo-slider スタイルでラップされたスライダー イメージを取得します。

php if ( have_posts() ) ループがスクリプトを壊しています。if($featuredImages!=NULL) 投稿にスライド画像がない場合にのみワードプレスのおすすめ画像を表示する if else ステートメントに含めようとしました。

コーディングに関するヘルプは素晴らしいでしょう。

ありがとう...リー

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

  }

?>
4

1 に答える 1

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
}

したがって、最初にプラグインを確認し、次にプラグイン画像の存在を確認し、それらのいずれかが否定的に返された場合は、サムネイル画像を表示します.

于 2014-02-14T20:45:45.307 に答える