2017-01-20 4 views
0

page.phpのWordpress ACFオプションに別のバナー画像を追加したいと思います。私はデフォルトのWordpressテンプレート用のデフォルトのバナー画像を作成できるように、これをやりたいと思います。私はそれを行う方法がわかりません。elseif文に別のACFオプションを追加するにはどうすればよいですか?

<?php if (is_page_template('template-projects.php')) { ?> 

    <?php 
    $banimage2 = get_field('banner_img', 'options'); // Array returned by Advanced Custom Fields 
    $banimage2Alt = $banimage2['alt']; // Grab, from the array, the 'alt' 
    $banimage2Width = $banimage2['width']; // Grab, from the array, the 'width' 
    $banimage2Height = $banimage2['height']; // Grab, from the array, the 'height' 
    $banimage2ThumbURL = $banimage2['sizes']['large']; //grab from the array, the 'sizes', and from it, the 'thumbnail' 
    ?> 

    <img class="box-banner" src="<?php echo $banimage2ThumbURL;?>" alt="<?php echo $banimage2Alt; ?>" width="<?php echo $banimage2Width; ?>" height="<?php echo $banimage2Height; ?>" /> 

<?php } elseif (is_singular('projects')) { ?> 

    <?php 
    $banimage3 = get_field('pd_banner', $post_id); // Array returned by Advanced Custom Fields 
    $banimage3Alt = $banimage3['alt']; // Grab, from the array, the 'alt' 
    $banimage3Width = $banimage3['width']; // Grab, from the array, the 'width' 
    $banimage3Height = $banimage3['height']; // Grab, from the array, the 'height' 
    $banimage3ThumbURL = $banimage3['sizes']['large']; //grab from the array, the 'sizes', and from it, the 'thumbnail' 
    ?> 

    <img class="box-banner" src="<?php echo $banimage3ThumbURL;?>" alt="<?php echo $banimage3Alt; ?>" width="<?php echo $banimage3Width; ?>" height="<?php echo $banimage3Height; ?>" /> 

<?php } else { ?> 
    <?php 
    $banimage = get_field('banner_img'); // Array returned by Advanced Custom Fields 
    $banimageAlt = $banimage['alt']; // Grab, from the array, the 'alt' 
    $banimageWidth = $banimage['width']; // Grab, from the array, the 'width' 
    $banimageHeight = $banimage['height']; // Grab, from the array, the 'height' 
    $banimageThumbURL = $banimage['sizes']['large']; //grab from the array, the 'sizes', and from it, the 'thumbnail' 
    ?> 
    <?php if(get_field('banner_img')): ?> 
    <img class="box-banner" src="<?php echo $banimageThumbURL;?>" alt="<?php echo $banimageAlt; ?>" width="<?php echo $banimageWidth; ?>" height="<?php echo $banimageHeight; ?>" /> 
    <?php endif; ?> 
<?php } ?> 

答えて

0

を私がした答えますステートメントの最後にELSEを追加してください。

<?php else: ?> 
    <img class="box-banner" src="<?php the_field('banner_img', 'options'); ?>" /> 

<?php endif; ?> 
0

私は私はあなたが何をしたいのか全く持ってわからないが、あなたのifelse文で新しい条件を追加するために、あなたはこのようにそれを追加することができます。

[...] 

<?php elseif (is_singular('projects')) : ?> 

    [...] 

<?php elseif ([YOUR CONDITION]) : ?> 

    [DO YOUR THING] 

<?php else : ?> 

    [...] 

<?php endif; ?> 
+0

私は私が必要とするかもしれないと思う私はそれをいじくり回すと表示されます。助けてくれてありがとう、私はフォローアップします。 – lala

関連する問題