简体   繁体   中英

Trouble with if (empty

I'm trying to set up a page with an image gallery where, if the alt field is empty, it'll display whatever is in the caption (at least one or the other will always have content). This is my current code, which is displaying nothing at all.

$image_all = wp_prepare_attachment_for_js($item->ID);

if (empty($image_all['alt'])) { 
    echo $image_all['caption']; 
} else { 
    echo $image_all['alt']; 
}

If I just put in echo $image_all['alt']; (or 'caption' ) it displays just fine. But using the if statement results in nothing displaying at all.

What am I doing wrong?

Well I feel pretty stupid right now. I was modifying code for the display page, but was trying to view the results from the search page. I really need to set this up with an include file so I only need to make changes in one place. I'm really sorry for wasting everyone's time. My original code works just fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM