0

Real php beginner here, sorry for the basic questions, but I didn't find any solution.

  1. question: I am looping through the children of a page in processwire. I got help in the processwire forum with this code:

              <?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; ?>
    

But, when I try to write it in regular PHP, I don't see the images on my website What am I writing wrong? I think the following php is the same as the above.

   <div class='single-product-wrapper'>

            <?php foreach ($page->children() as $product){
              echo $product->img->first()->url;
              echo $product->inhalt1; 


            }

            ?>

          </div> 

2. question:

How do I write a resize of the images into thumbnails in shorthand php? Now I get the fullsize images on the page.

Thanks a lot Jakob

Kuba Degi
  • 23
  • 1
  • 3

1 Answers1

1

1- You are not seeing the image on your web page because you are printing only the URL of the image. But you are not saying the browser to print it.

// 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 - You can pass a small size on img tag as height and weigth atributes. Or better use CSS to format the image size

WeezHard
  • 1,982
  • 1
  • 16
  • 37