简体   繁体   English

如何在Wordpress中为get_post_meta编写if语句

[英]How to write if statement for get_post_meta in Wordpress

I'm trying to right an if statement for get_post_meta. 我试图纠正get_post_meta的if语句。 I want to display the info if something is there, if there is nothing, don't display anything. 我想显示信息,如果有东西,如果什么都没有,什么都不显示。 Here is an example I am working with, with no luck. 这是我正在处理的示例,没有运气。

if(get_post_meta()); echo '<a href="'.get_post_meta($post->ID, 'text', true).'">'; endif;

Any help is appreciated. 任何帮助表示赞赏。 Thanks. 谢谢。

You've made an error in the syntax. 您在语法上犯了一个错误。 Use 采用

if($condition): statements; endif;
              ^

instead of 代替

if($condition); statements; endif;
              ^

So your code would be 所以你的代码是

if(get_post_meta()):
    echo '<a href="'.get_post_meta($post->ID, 'text', true).'">';
endif;

That's the alternative syntax for control structures . 这是控制结构替代语法
You can always use the standard one 您可以随时使用标准的

if($conition) {
    // statements
    // .....
}
else { 
    // otherweise
}

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

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