Wordpress用名称替换变量

时间:2014-03-15 15:58:54

标签: wordpress

我有这段代码

<'.if (get_post_meta($post->ID,"_as_roomtype",true) == 'DE').'>
<a href="'.get_permalink().'" class="readnow" >"---NAME---"</a>

我有&#34; meta_value&#34;喜欢&#34; DE&#34;,&#34;英国&#34;,&#34; SP&#34;

我需要做出类似的事情。

if the value on "meta_value" = "DE" show Germany on "---NAME---"
if the value on "meta_value" = "UK" show United Kingdom on "---NAME---"
if the value on "meta_value" = "SP" show Spain on "---NAME---"

我该怎么做?

1 个答案:

答案 0 :(得分:1)

尝试这样的事情:

<?php
$meta_values = array('DE' => 'Germany', 'UK' => 'United Kingdom', 'SP' => 'Spain');
if ($meta_key = get_post_meta($post->ID,"_as_roomtype",true)):
?>
<a href="<?php echo get_permalink() ?>" class="readnow" ><?php echo $meta_values[$meta_key]; ?></a>