私は現在、開発中のワードプレス サイトで高度なカスタム フィールド プラグインを使用しており、非常に便利であることが証明されています。
スタッフ メンバーのリストを生成するのに役立つリピーター アドオンを購入しました。ただし、スタッフ メンバーが使用できる画像が常にあるとは限らないので、代替画像を使用するか、 http://placehold.itのようなオンライン プレースホルダー画像サービスを使用したいと思いますか?
コードは次のとおりです。
<?php if(get_field('about_the_practioner')): ?>
<?php while(the_repeater_field('about_the_practioner')): ?>
<article class="colleague_excerpts">
<figure>
<?php if(get_field('image')): ?>
<img src="<?php the_field('image' ) ?>" alt="<?php the_sub_field('image_alt_text'); ?>">
<?php else: ?>
<img src="http://placehold.it/160x160&text=Awaiting Image">
<?php endif; ?>
</figure>
<div class="description">
<header>
<h4><?php the_sub_field('header')?><span><?php the_sub_field('title')?></span></h4>
</header>
<p><?php the_sub_field('text') ?></p>
<a href="<?php the_sub_field('page_link')?>" class="button"><?php the_sub_field('page_link_text') ?></a>
</div>
<hr>
</article>
<?php endwhile; ?>
<?php endif; ?>
注目の画像が利用できない場合に代替画像を作成するために使用される条件文を見てきました。この場合、画像が呼び出される時点で同様のことを試しましたが、php が苦手で、画像フィールドにデータが入力されていても、フォールバック画像のみが Web ページに取り込まれます。どんな助けでも大歓迎です。