WordPress 条件自定义字段
我想在 WordPress 安装的单页中输出自定义字段。 基本上,我想在页面中输出相关的创意通用许可类型。因此,基本上,带有 cc-license
键的自定义字段可能只有一个值,但该值必须是六个创意通用许可证之一。
假设我已经插入了密钥 cc-license 的值。这是我的代码:
<?php
$nilai = get_post_meta($post->ID, 'cc-license', true);
echo $nilai; //just want to check the output,its ok!
if ($nilai = 'Attribution Non-commercial Share Alike') { ?>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>
<?php } ?>
问题是,如果我将值更改为任何文本,它仍然会实现条件语句中的 HTML 代码。哪一部分是错误的?
I want to output a custom field in my single page of my WordPress install.
Basically, I want to output the related creative common license type in the page. So basically the custom field with key cc-license
may have one value only, but the value must be one of the six creative common licenses.
Assuming I already insert the value for the key cc-license. So here is my code:
<?php
$nilai = get_post_meta($post->ID, 'cc-license', true);
echo $nilai; //just want to check the output,its ok!
if ($nilai = 'Attribution Non-commercial Share Alike') { ?>
<a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/"><img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons Attribution-ShareAlike 3.0 Unported License</a>
<?php } ?>
The problem is, if I change the value to any text, it still implement the HTML code in the conditional statement. Which part is wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个,我想你可能刚刚错过了一个=
Try this, I think you might have just missed a =