[英]PHP conditional echo text instead HTML
I'm trying to create a conditional for a theme in a Wordpress, If the meta exist show this... else show that. 我正在尝试为Wordpress中的主题创建条件,如果该meta存在,请显示此...否则显示。
<?php
$scene_trailer = get_post_meta($post->ID, 'scene_trailer', true);
if ( $scene_trailer ) {
echo htmlentities('<div style="width: 645px; height: 364px; overflow: hidden">
<iframe src="http://tvguide.com/<?php $key="scene_number"; echo get_post_meta($post->ID, $key, true); ?>/" width="645" height="430" scrolling="no" frameborder="0" style="position: relative; top: -36px"></iframe></div>');
}
else {
echo '<img src="http://i0.tvguide.com/<?php $key="scene_number"; echo get_post_meta($post->ID, $key, true); ?>/576x324.jpg" width="576" height="324" alt="" />';
}
?>
My code returns this as plain text: 我的代码以纯文本形式返回:
<div style="width: 645px; height: 364px; overflow: hidden"> <iframe src="http://tvguide.com<?php $key="scene_number"; echo get_post_meta($post->ID, $key, true); ?>/" width="645" height="430" scrolling="no" frameborder="0" style="position: relative; top: -36px"></iframe></div>
Can someone please show me what I'm doing wrong? 有人可以告诉我我在做什么错吗? Thanks!
谢谢!
You have write wrong php syntax Please try below code. 您编写了错误的php语法,请尝试以下代码。
<?php
$scene_trailer = get_post_meta($post->ID, 'scene_trailer', true);
if ($scene_trailer) {
$key = "scene_number";
$scene_number = get_post_meta($post->ID, $key, true);
echo htmlentities('<div style="width: 645px; height: 364px; overflow: hidden">
<iframe src="http://tvguide.com/' . $scene_number . '" width="645" height="430" scrolling="no" frameborder="0" style="position: relative; top: -36px"></iframe></div>');
} else {
echo '<img src="http://i0.tvguide.com/scenes/' . $scene_number . '/576x324.jpg" width="576" height="324" alt="" />';
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.