wordpressでサイトを作っています。
フッターに各SNSのアイコンを付けてリンクを貼りたいと思っています。
こちらの記事を参考にオプションページを作ってadvanced custom fields proで各SNSリンクの入力欄を作りました。
footer.phpには以下のように記述をしました。
<footer id="footer_wrap"> <div id="copyright_wrap"> <ul class="sns_icon"> <li><a href="<?php the_field('facebook_url','option'); ?>" target="_blank"><i class="fab fa-facebook-square"></i></a></li> <li><a href="<?php the_field('instagram_url','option'); ?>" target="_blank"><i class="fab fa-instagram"></i></a></li> <li><a href="<?php the_field('twitter_url','option'); ?>" target="_blank"><i class="fab fa-twitter-square"></i></a></li> </ul> <p id="copyright"><small>© 2019 xxxxxx</small></p> </div> <div id="pagetop"><a href=".header" class="button"><span class="fas fa-arrow-up"></span></a></div> </footer> <?php wp_footer(); ?> </div> </body> </html>
これで正しく表示されたのですが、URLの入力のない場合にはそのアイコンは非表示にしたいと思い、下記のように修正しました。
<footer id="footer_wrap"> <div id="copyright_wrap"> <ul class="sns_icon"> <?php if(post_custom('facebook_url','option')): ?> <li><a href="<?php the_field('facebook_url','option'); ?>" target="_blank"><i class="fab fa-facebook-square"></i></a></li> <?php endif; ?> <?php if(post_custom('instagram_url','option')): ?> <li><a href="<?php the_field('instagram_url','option'); ?>" target="_blank"><i class="fab fa-instagram"></i></a></li> <?php endif; ?> <?php if(post_custom('twitter_url','option')): ?> <li><a href="<?php the_field('twitter_url','option'); ?>" target="_blank"><i class="fab fa-twitter-square"></i></a></li> <?php endif; ?> </ul> <p id="copyright"><small>© 2019 xxxxxxxx</small></p> </div> <div id="pagetop"><a href=".header" class="button"><span class="fas fa-arrow-up"></span></a></div> </footer> <?php wp_footer(); ?> </div> </body> </html>
ですが、URLの入力があるにも関わらず、すべて非表示になっていまいます。
入力し直して「更新」しても変わらず。
分岐の書き方が間違っているのでしょうか?通常のページはこれでいけたのですが。。
それともオプションページを使うときには特殊な書き方があるのでしょうか??
PHP初心者です。解決策がありましたらアドバイスお願いします!
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/28 09:12