简体   繁体   English

回显字符串中的php变量

[英]php variable in a echo string

I'm customizing a wordpress for the first time so I'm pretty new with PHP langage and something is driving me crazy. 我是第一次自定义wordpress,所以我对PHP语言非常陌生,这使我发疯。 I wrote that function to transform my HTML5/CSS3/JQUERY layout into a CMS: 我编写了将该函数转换为HTML5 / CSS3 / JQUERY布局为CMS的功能:

<?php $property = simple_fields_values("pillow_front");
  foreach ($property as $value) {
    echo "<div class='solo'>";
      echo "<div class='box coussin'>";
        echo "<div class='outImg'><img src='" . wp_get_attachment_url($value) . "'/></div>";
      echo "</div>";
    echo "</div>";
  }
?>

But in the front-end it doesn't work and when I look at the code it appears that the img tag is not closed properly: 但是在前端它不起作用,当我查看代码时,似乎img标签未正确关闭:

<div class="solo">
  <div class="box coussin" style="width: 328px; height: 328px;">
    <div class="outImg" style="opacity: 1;">
      <img src="http://localhost:8888/wp-content/uploads/2014/01/021.jpg" style="width: 328px; height: 328px;">
    </div>
  </div>
</div>

I didn't really well understoud if the . 如果不是,我不是很了解。 in PHP was the exact equivalent of the + in javascript but I tried a lots of thing and I can get that tag to be properly closed ! 在PHP中与javascript中的+完全等效,但是我尝试了很多事情,并且可以将该标签正确关闭!

Thank you 谢谢

You can print in another system, something like this: 您可以在另一个系统中进行打印,如下所示:

<?php 
$property = simple_fields_values("pillow_front");
 foreach ($property as $value) {
 ?>
  <div class='solo'>
   <div class='box coussin'>
    <div class='outImg'><img src="<?php print wp_get_attachment_url($value);?>"/></div>
   </div>
  </div>
 <?php
 }
 ?>

Please note that i put the echo of the function only because i do not know how it works, it can be not necessary, use php only when needed. 请注意,我仅把函数的回声放进去是因为我不知道它是如何工作的,可能没有必要,仅在需要时才使用php。

Or just a bit more MVC-Pattern or in that case just MV? 还是只是更多的MVC模式,或者在那种情况下只是MV? ;) Try this one without Wordpress. ;)不用Wordpress尝试一下。

<?php

    //Init
    $property = simple_fields_values("pillow_front");
    $template = '<div class="solo">
       <div class="box coussin">
        <div class="outImg"><img src="{MARKER:FRONT}" /></div>
       </div>
      </div>';

    foreach ($property as $value) {
        echo str_replace(array('{MARKER:FRONT}'), array($value), $template);
    }
?>

And as i know wordpress view, your code style is not confirm to WP-Styleguide. 而且据我所知,wordpress视图的代码风格尚未向WP-Styleguide确认。 WP is using HTML/PHP Templating. WP正在使用HTML / PHP模板。 In WP you view need to look like this. 在WP中,您需要看起来像这样。

<?php foreach(simple_fields_values("pillow_front") as $value): ?>
<div class='solo'>
    <div class='box coussin'>
        <div class='outImg'><img src="<?php echo htmlentities(value): ?>"/></div>
    </div>
</div>
<?php endforeach; ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM