我正在尋找在wordpress循環中創建條件。如果沒有圖像,然後圖像框(.thumbHome {顯示:無})如果循環中沒有圖像,則隱藏Div
這是我function.php
function getThumbImages($postId) {
$iPostID = get_the_ID();
$arrImages =& get_children('post_type=attachment&post_mime_type=image&post_parent=' . $iPostID);
if($arrImages) {
$arrKeys = array_keys($arrImages);
$iNum = $arrKeys[0];
$sThumbUrl = wp_get_attachment_thumb_url($iNum, $something);
$sImgString = '<img src="' . $sThumbUrl . '" alt="thumb Image" title="thumb Image" />';
echo $sImgString;}
else {
echo '<script language="javascript">noImage()</script>';
}
}
而且我的javascript:
window.onload = noImage();
function noImage(){
document.getElementByClassName('.thumbHome').css.display = 'none';
}
我想:
window.onload = noImage();
function noImage(){
$('.thumbHome').addClass('hide');
}
RESULT:class hide added to all loop
我不能以另一種方式來看待它,因爲im仍然是編碼新手。
THX
如果實際上有任何圖像,您可以將該框默認爲隱藏,並在循環完成後簡單地發出覆蓋css。你已經獲得了服務器端的所有信息,不妨使用它。當然,使用javascript的人不會看到任何圖片,但這是他們的問題。 – 2011-01-11 21:02:44