2016-11-07 32 views
0

在我的WordPress MySQL DB中,有一個meta_keywp_postmeta表,其值爲mazda-certified。此外還有一個與meta_key關聯的meta_value,它的內容如下:「是」或「否」。如果在WordPress中meta_key = x AND meta_value = y,我該如何顯示圖片?

我需要弄清楚如何顯示圖像當且僅當meta_key=mazda-certifiedmeta_key=yes

任何幫助,這是非常讚賞。

我一直在研究這個小時,不幸的是只提取關於UserMeta的信息。

回答

1

因爲我真的不知道該怎麼想顯示你的圖像,實現這一目標我最簡單的方法,是創建一個簡碼,你就可以你想

在你的functions.php任何地方文件:

add_shortcode('certified-image', 'add_certified_image'); 

    function add_certified_image($atts, $content = ""){ 
     global $post; 

     if(get_post_meta($post->ID,'mazda-certified', true) == 'yes'){ 
      $content = '<img src="image-yes.jpg"/>'; 
     } 
     else{ 
      $content = '<img src="image-no.jpg"/>'; 
     } 
     return $content; 
    } 

在模板:

echo do_shortcode('[certified-image]'); 

這是一個簡單的例子,瞭解更多關於add_shortcode on the codex將屬性添加到簡碼。

+0

感謝您的幫助!我意識到什麼是問題,這是'是'這個詞。在MYSQL數據庫中被列爲'是'。 – CrawlerWebSolutions

相關問題