我正在使用CMS ProscessWire。如何在foreach循環PHP中用if語句更改圖像?
我有一個工作的foreach循環,顯示孩子的標題和5個鏈接。鏈接顯示爲圖像。這工作完美無瑕。但是,我想要一個空白的鏈接黑白圖像來顯示沒有鏈接。所以我做了一個if語句。但是,當我把if語句放在循環中時,顯示的唯一子節點就是具有空鏈接的節點。
有誰知道tot如何解決這個問題?我認爲這是一件簡單的事情,但無法弄清楚。
PHP-代碼:
$rdio='rdio.png';
$itunes='itunes.png';
$xbox='xbox.png';
$googleplay='googleplay.png';
$spotify='spotify.png';
$deezer='deezer.png';
foreach($page->children as $child)
if(!$child->Rdio) {
$rdio='rdiog.png';
}
else
{
$rdio='rdio.png';
}
echo "<ul style='background-color:#CCC;'>"."<li><h1>{$child->title}</h1></li>".<li><a class='rdio' href='{$child->Rdio}'><img src='../site/templates/img/$rdio' alt='rdio'/></a></li>"."<li><a class='itunes' href='{$child->iTunes}'><img src='../site/templates/img/$itunes' alt='itunes'/></a></li>"."<li><a class='xbox' href='{$child->Xbox}'><img src='../site/templates/img/$xbox' alt='xbox'/></a></li>"."<li><a class='googleplay' href='{$child->GooglePlay}'><img src='../site/templates/img/$googleplay' alt='googleplay'/></li>"."<li><a class='spotify' href='{$child->Spotify}'><img src='../site/templates/img/$spotify' alt='spotify'/></a></li>"."<li><a class='deezer' href='{$child->Deezer}'><img src='../site/templates/img/$deezer' alt='deezer'/></a></li>"."</ul><br/>";
請更多的細節解釋,並添加一些代碼,以便我們可以瞭解如何幫助你 – Syd