<?php
if(get_field('member_only_content')){
echo "do something";
}else{
echo "do something else";
}
?>
如何在显示"do something"
的位置插入HTML代码?删除echo "do something";
并粘贴HTML代码时,Wordpress网站崩溃。
答案 0 :(得分:4)
关闭并打开PHP块,如下所示:
if(get_field('member_only_content')){
?>
<html></html>
<?php
} else{
?>
<html></html>
<?php
}
您也可以使用PHP的替代语法:
if(get_field('member_only_content')): ?>
<html></html>
<?php else: ?>
<html></html>
<?php endif;
答案 1 :(得分:2)
喜欢这个!
<?php
if(get_field('member_only_content')) : ?>
<div>Html stuff</div>
<?php else : ?>
<div>More Html stuff</div>
<?php endif;
答案 2 :(得分:2)
用HTML代替字符串。
<?php
if(get_field('member_only_content')){
echo "<your>HTML here</your>";
}else{
echo "<other>HTML</other>";
}
?>
你也可以打破PHP标签
<?php
if(get_field('member_only_content')){
?>
<your>HTML here</your>
<?
}else{
?>
<other>HTML</other>
<?
}
?>
答案 3 :(得分:1)
或者您可以使用&lt;&lt;&lt;语句:
echo <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;
答案 4 :(得分:0)
示例代码
echo("<h1>This is a sample</h1>");
答案 5 :(得分:0)
那是因为你将HTML代码放在php标签(<?php ?>
)中。此标记内的文本被解释为PHP指令,因此它不会呈现HTML。在PHP文件中有两种通用方式呈现HTML:
<?php
if (get_field ('member_only_content')) {
echo "<span>Put HTML here</span>";
}
else {
echo "<span>Put HTML here</span>";
}
?>
<?php if (get_field ('member_only_content')): ?>
<span>Put HTML here</span>
<?php else: ?>
<span>Put HTML here</span>
<?php endif;?>
答案 6 :(得分:0)
<?php
if(get_field('member_only_content')){
echo "<div style='background-color: #888888'>This is a simple string between div's, make sure you've to be careful while inserting too many single and double quotes in this string as well as inline styles</div>";
}else{
echo "do something else";
}
?>
在字符串中插入引号时要小心。