<?php if(strlen(get_post_meta($post->ID, \'recent_action\', true)) !== 0){ ?>
<a class="button" href="<?php echo get_post_meta($post->ID, "recent_action", true); ?>">Recent Action Link</a>
<?php } elseif(strlen(get_post_meta($post->ID, \'related_link\', true)) !== 0){ ?>
<a class="button" href="<?php echo get_post_meta($post->ID, "related_link", true); ?>">Related Link</a>
<?php } elseif(strlen(get_post_meta($post->ID, \'imp_docs_link\', true)) !== 0){ ?>
<a class="button" href="<?php echo get_post_meta($post->ID, "imp_docs_link", true); ?>">Important Documents Link</a>
<?php } ?>
或者更好(情况取决于可靠性的提高):
<?php if(!empty(get_post_meta($post->ID, \'recent_action\', true))){ ?>
<a class="button" href="<?php echo get_post_meta($post->ID, "recent_action", true); ?>">Recent Action Link</a>
<?php } elseif(!empty(get_post_meta($post->ID, \'related_link\', true))){ ?>
<a class="button" href="<?php echo get_post_meta($post->ID, "related_link", true); ?>">Related Link</a>
<?php } elseif(!empty(get_post_meta($post->ID, \'imp_docs_link\', true))){ ?>
<a class="button" href="<?php echo get_post_meta($post->ID, "imp_docs_link", true); ?>">Important Documents Link</a>
<?php } ?>
如果确定返回的是字符串,则使用strlen()。对于所有其他情况,请使用empty()。