[英]Streamline these if statements and output them with their values
在Wordpress上使用主題選項時,有沒有一種方法可以簡化我的流程?
當前,例如,當我創建社交鏈接菜單時(例如,選項值為鏈接URL),我會使用類似的設置;
$twitter = of_get_option('twitter');
$facebook = of_get_option('facebook');
$google-plus = of_get_option('google-plus');
if ($twitter){
echo '<li class="twitter"><a href="'.$twitter.'"><i class="fa fa-twitter"></i></a></li>';
}
if ($facebook){
echo '<li class="facebook"><a href="'.$facebook.'"><i class="fa fa-facebook"></i></a></li>';
}
if ($google-plus){
echo '<li class="google-plus"><a href="'.$google-plus.'"><i class="fa fa-google-plus"></i></a></li>';
}
我確定必須有一種更簡單,更精簡的方法來做到這一點?
任何幫助將不勝感激。
我將其包裝在一個函數中。
function getOption($op) {
$link = of_get_option($op);
if($link)
echo '<li class="'.$op.'"><a href="'.$link.'"><i class="fa fa-'.$op.'"></i></a></li>';
}
getOption('twitter');
getOption('facebook');
getOption('google-plus');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.