简体   繁体   English

php 将 html 分离成 if 语句 wordpress

[英]php separate html into if statement wordpress

a little question about why something that should work in theory doesn't work for me.关于为什么理论上应该有效的东西对我不起作用的一个小问题。

Target.目标。 Separate the html code from the if loop将 html 代码从 if 循环中分离出来

example:例子:

if ($condition){
    echo "no";
}
else{?>
     <p>yes</p>
<?php}?>

but if copy and paste this in my custom theme in wordpress:但如果将其复制并粘贴到 wordpress 的自定义主题中:

<?php
$AMC_metakey_video = get_post_meta( $post->ID, 'metakey_AMC_video', true );

    if ($AMC_metakey_video === ''){
        echo "Gratis";
    }
    else{?>
        <p>no</p>
    <?php}?>

i have blank result... i don't know, why?我有空白结果...我不知道,为什么?

Try this尝试这个

<?php $AMC_metakey_video = get_post_meta( $post->ID, 'metakey_AMC_video', true ); ?>

   <?php if(empty($AMC_metakey_video)): ?>
        <p>Gratis</p> or any HTML

   <?php else: ?>
        else HTML
   <?php endif; ?>

Hope it helps.希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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