Php Echo EOT-如何在其中使用循环和条件运算符?
我有一个关于如下代码的问题:Php Echo EOT-如何在其中使用循环和条件运算符?,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我有一个关于如下代码的问题: echo <<<EOT <div class="quick-view-list nav"> How can i use loop or conditional operator here? <a class="active" href="$similarProduct0"> <img src
echo <<<EOT
<div class="quick-view-list nav">
How can i use loop or conditional operator here?
<a class="active" href="$similarProduct0">
<img src="$similarProductImg0" alt="Similar Product" width="100px" height="112px">
</a>
<a href="$similarProduct1">
<img src="$similarProductImg1" alt="Similar Product" width="100px" height="112px">
</a>
<a href="$similarProduct2">
<img src="$similarProductImg2" alt="Similar Product" width="100px" height="112px">
</a>
</div>
EOT;
echo您是否尝试过ob\u start
和ob\u get\u clean
?您的代码可以这样编写:
<?php // assuming php open here...
ob_start(); ?>
<div class="quick-view-list nav">
<?php
// do your conditional operator here....
?>
<a class="active" href="<?php echo $similarProduct0; ?>">
<img src="<?php echo $similarProductImg0; ?>" alt="Similar Product" width="100px" height="112px">
</a>
<a href="<?php echo $similarProduct1; ?>">
<img src="<?php echo $similarProductImg1; ?>" alt="Similar Product" width="100px" height="112px">
</a>
<a href="<?php echo $similarProduct2; ?>">
<img src="<?php echo $similarProductImg2; ?>" alt="Similar Product" width="100px" height="112px">
</a>
</div>
<?php
echo ob_get_clean();
您是否尝试过ob\u start
和ob\u get\u clean
?您的代码可以这样编写:
<?php // assuming php open here...
ob_start(); ?>
<div class="quick-view-list nav">
<?php
// do your conditional operator here....
?>
<a class="active" href="<?php echo $similarProduct0; ?>">
<img src="<?php echo $similarProductImg0; ?>" alt="Similar Product" width="100px" height="112px">
</a>
<a href="<?php echo $similarProduct1; ?>">
<img src="<?php echo $similarProductImg1; ?>" alt="Similar Product" width="100px" height="112px">
</a>
<a href="<?php echo $similarProduct2; ?>">
<img src="<?php echo $similarProductImg2; ?>" alt="Similar Product" width="100px" height="112px">
</a>
</div>
<?php
echo ob_get_clean();
只是试过了,它不起作用。没有显示任何内容。无论如何,谢谢。它应该可以工作,这里有一个例子,在演示中,你需要点击“执行代码”按钮来查看输出的工作情况。因为我的错误,它没有起作用。。。。谢谢只是试过了,它不起作用。没有显示任何内容。无论如何,谢谢。它应该可以工作,这里有一个例子,在演示中,你需要点击“执行代码”按钮来查看输出的工作情况。因为我的错误,它没有起作用。。。。谢谢