简体   繁体   中英

expecting statement -php syntax | if-else

 <?php if ( wp_get_attachment_image($item['image']['id'], 'home-post-thumbnail')  !='' ) { ?>
         <?php echo wp_get_attachment_image( $item['image']['id'], 'home-post-thumbnail' ); } ?>
                                          <?php else {
                        ?> <img class="img-responsive img-whp" src="<?php echo plugin_dir_url( __FILE__ ) . '/6-450x450.jpg'; ?>">
                                        <?php  } ?>

I get critical error.phpstorms says that expecting statements.I couldnt find a solution

You cannot "interrupt" the PHP code after the closing { of the if and before the else keyword.

Cleaned up version:

<?php if (wp_get_attachment_image($item['image']['id'], 'home-post-thumbnail') != '') {
    echo wp_get_attachment_image($item['image']['id'], 'home-post-thumbnail');
} else {
    ?><img class="img-responsive img-whp" src="<?php echo plugin_dir_url( __FILE__ ) . '/6-450x450.jpg'; ?>"><?php
} ?>

To avoid such errors, try learning and following a coding standard, eg PSR-12 .

Since you are working with WordPress, here is WP's coding standard for PHP: https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/

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