我看不出这里有什么不正确的地方,我试图在所有(和一些)选项都为空的情况下隐藏整个元素,但它隐藏了所有内容,即使至少填充了选项。
我的代码:
<?php $sitename = get_bloginfo( \'description\' );
$phone1 = get_option( \'show_phone1\' );
$phone2 = get_option( \'show_phone2\' );
$email = get_option( \'show_email\' );
$address1 = get_option( \'show_address1\' );
$address2 = get_option( \'show_address2\' );
$town = get_option( \'show_town\' );
$county = get_option( \'show_county\' );
$postcode = get_option( \'show_postcode\' );
if ( ! empty( $sitename ) && ( ! empty( $phone1 ) || ! empty( $phone2 ) ) && ! empty( $email ) && ( ! empty( $address1 ) && ! empty( $address2 ) ) && ! empty( $town ) && ! empty( $county ) && ! empty( $postcode ) ) : ?>
<div class="site-contact">
<?php if ( ! empty( $sitename ) ) : ?>
<span><?php echo get_bloginfo( \'name\' ); ?></span>
<?php endif; if ( ! empty( $phone1 ) ) : ?>
<span><?php echo get_option( \'show_phone1\' ); ?></span>
<?php endif; if ( ! empty( $phone2 ) ) : ?>
<span><?php echo get_option( \'show_phone2\' ); ?></span>
<?php endif; if ( ! empty( $email ) ) : ?>
<span><a href="mailto:<?php echo get_option( \'show_email\' ); ?>" title="Send and email to <?php echo esc_attr( get_bloginfo( \'name\', \'display\' ) ); ?>"><?php echo get_option( \'show_email\' ); ?></a></span>
<?php endif; if ( ! empty( $address1 ) ) : ?>
<span><?php echo get_option( \'show_address1\' ); ?></span>
<?php endif; if ( ! empty( $address2 ) ) : ?>
<span><?php echo get_option( \'show_address2\' ); ?></span>
<?php endif; if ( ! empty( $town ) ) : ?>
<span><?php echo get_option( \'show_town\' ); ?></span>
<?php endif; if ( ! empty( $county ) ) : ?>
<span><?php echo get_option( \'show_county\' ); ?></span>
<?php endif; if ( ! empty( $postcode ) ) : ?>
<span><?php echo get_option( \'show_postcode\' ); ?></span>
<?php endif; ?>
</div><!-- .site-contact -->
<?php endif; ?>
非常感谢您的帮助,请记住我(显然)不编写PHP。。我只是在试着编辑一下。。这总是很有趣。