我有一个错误:
解析错误:语法错误,意外'<'在第197行的/home/dgsite81/public_html/dgprint/wp-content/themes/dgprint/taxonomy-product_category.php
代码PHP:
<?php
$queried_object = get_queried_object();
$cat_content = get_field('category_content', $queried_object);
$imagine2= get_field('imagine2',$queried_object);
$imagine3= get_field('imagine3',$queried_object);
$imagine4= get_field('imagine4',$queried_object);
$imagine5= get_field('imagine5',$queried_object);
$fields = array("cat_content","imagine2","imagine3","imagine4","imagine5");
<ul> //here is the line with error
<?php foreach($fiedls as $value) { ?>
<li><?php echo $value; ?></li>
<?php } ?>
</ul>
?>
如何修复此错误?我没有意识到我应该添加括号以及确切位置。
答案 0 :(得分:1)
您正在混合使用PHP和HTML。您需要将PHP代码括在<?php ?>
括号中......
$fields = array("cat_content","imagine2","imagine3","imagine4","imagine5");
?> <!-- This tells the PHP parser to stop parsing as PHP code -->
<ul>
答案 1 :(得分:0)
您在php标记中使用HTML,您可以执行echo "<ul>"
或关闭PHP,然后执行ul
,如下所示:
<?php
$queried_object = get_queried_object();
$cat_content = get_field('category_content', $queried_object);
$imagine2= get_field('imagine2',$queried_object);
$imagine3= get_field('imagine3',$queried_object);
$imagine4= get_field('imagine4',$queried_object);
$imagine5= get_field('imagine5',$queried_object);
$fields = array("cat_content","imagine2","imagine3","imagine4","imagine5"); ?> <------- this thing here
<ul> //here is the line with error
<?php foreach($fiedls as $value) { ?>
<li><?php echo $value; ?></li>
<?php } ?>
</ul>
?>
答案 2 :(得分:0)
你只需要在那行之前关闭php脚本
<?php
$queried_object = get_queried_object();
$cat_content = get_field('category_content', $queried_object);
$imagine2= get_field('imagine2',$queried_object);
$imagine3= get_field('imagine3',$queried_object);
$imagine4= get_field('imagine4',$queried_object);
$imagine5= get_field('imagine5',$queried_object);
$fields = array("cat_content","imagine2","imagine3","imagine4","imagine5");
?>
<ul>
<?php foreach($fiedls as $value) { ?>
<li><?php echo $value; ?></li>
<?php } ?>
</ul>
?>
答案 3 :(得分:0)
你缺少关闭php的标签,所以php会自动尝试解析它。
正确的代码:
$fields = array("cat_content","imagine2","imagine3","imagine4","imagine5"); ?>
<ul> //here is the line with error
答案 4 :(得分:0)
是的,因为您直接在PHP代码中使用了HTML标记。试试这个:
<?php
$queried_object = get_queried_object();
$cat_content = get_field('category_content', $queried_object);
$imagine2= get_field('imagine2',$queried_object);
$imagine3= get_field('imagine3',$queried_object);
$imagine4= get_field('imagine4',$queried_object);
$imagine5= get_field('imagine5',$queried_object);
$fields = array("cat_content","imagine2","imagine3","imagine4","imagine5");
?>
<ul>
<?php foreach($fiedls as $value) { ?>
<li><?php echo $value; ?></li>
<?php } ?>
</ul>
答案 5 :(得分:0)
这是基本语法,请更好地记录自己... 试试这个:
<?php
$queried_object = get_queried_object();
$cat_content = get_field('category_content', $queried_object);
$imagine2= get_field('imagine2',$queried_object);
$imagine3= get_field('imagine3',$queried_object);
$imagine4= get_field('imagine4',$queried_object);
$imagine5= get_field('imagine5',$queried_object);
$fields = array("cat_content","imagine2","imagine3","imagine4","imagine5");
echo '
<ul>';
foreach($fiedls as $value){
echo '
<li>'.$value.'</li>';
}
echo '
</ul>';
?>