PHP初学者需要掌握foreach循环


PHP beginner needs a hand with foreach loop

真正的php初学者在这里,抱歉的基本问题,但我没有找到任何解决方案。

  1. 问题:我在processwire中循环遍历页面的子节点。我在processwire论坛上得到了以下代码的帮助:

              <?php foreach ($page->children() as $product): ?>
            <div class='single-product-wrapper'>
              <?php $thumb = $img->size(100, 100); ?>
              <img src="<?php echo $product->thumb->first()->url; ?> "/>
              <p><?php echo $product->inhalt1; ?></p>
            </div>
          <?php endforeach; ?>
    

但是,当我尝试用常规PHP编写它时,我在我的网站上看不到图像我写错了什么?我想下面的php和上面的是一样的

   <div class='single-product-wrapper'>
            <?php foreach ($page->children() as $product){
              echo $product->img->first()->url;
              echo $product->inhalt1; 

            }
            ?>
          </div> 

2。问题:

我如何写一个缩略图的缩略图在速记php的大小调整?现在我在页面上得到了完整尺寸的图像。

非常感谢Jakob

1-你没有在网页上看到图像,因为你只打印了图像的URL。但是您并没有让浏览器打印它。

// This line will print only the URL
echo $product->img->first()->url;
// but this will print the img tag with the URL. Browser will show the image
<img src="<?php echo $product->thumb->first()->url; ?>">

2 -你可以传递一个小尺寸的img标签的高度和重量属性。或者最好使用CSS来设置图像的大小