簡體   English   中英

如何在Wordpress中為get_post_meta編寫if語句

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

我試圖糾正get_post_meta的if語句。 我想顯示信息,如果有東西,如果什么都沒有,什么都不顯示。 這是我正在處理的示例,沒有運氣。

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

任何幫助表示贊賞。 謝謝。

您在語法上犯了一個錯誤。 采用

if($condition): statements; endif;
              ^

代替

if($condition); statements; endif;
              ^

所以你的代碼是

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

這是控制結構替代語法
您可以隨時使用標准的

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM