How to show (style) xml product feed into php

I would like to show the content of an xml file in a way that it shows the title, image, price and button with external link to the website.

Construction of the xml:

 <title>
 <![CDATA[ here comes the title ]]>
 </title>
 <description>
 <![CDATA[ here you can find the description of the product. ]]>
 </description>
 <link>https://www.linktoproduct.com</link>
 <g:product_type>
 <![CDATA[ brand1 &gt; brand2 &gt; brand3 &gt; brand ]]>
 </g:product_type>
 <g:image_link>https://www.linktoproduct.com/imageproduct.jpg</g:image_link>
 <g:price>
 <![CDATA[ 35.10 EUR ]]>
 </g:price>

This is the code I have so far:

 <style>
 .title{
  font-weight: bold;
  font-size: 24px;
  color: seagreen;
  }
 .description{
  font-weight: bold;
  font-size: 20px;
  color: #bbb;
  }
  .link{
    outline: none;
    border: none;
    color: #fff;
    font-weight: 600;
    font-size: 14px;
    background-color: red;
    border: 1px solid red;
    border-radius: 50px;
    padding: 10px 25px;
    line-height: 24px;
    margin-bottom: 9px;
    transition: 0.3s;
    cursor: pointer;
     }
     .col-md-4 {
     position: relative;
     min-height: 1px;
     padding-left: 15px;
     padding-right: 15px;
     }  
     @media (min-width: 992px) {
     .col-md-4 {
     width: 33.33333333%;
     float: left;
     }
 </style>
 <?php
 $xml_data =    simplexml_load_file("https://www.website.com/productfeed.xml") or 
 die("Error: Object Creation failure");

 foreach ($xml_data->children() as $data)
 {
     echo "<div class='col-md-4'>";
     echo "<div class='title'>";
     echo $data->title ."<br>";
     echo "</div>";
     echo "<div class='description'>";
     echo $data->description ."<br> ";
     echo "</div>";
     echo "<div class='link'>";
     echo "<a href='$data->link' target='_blank'>koop nu</a>";
     echo "</div>";
     echo "</div>";

 }

 ?>

but it gives me these issues:

1/ how to show the price and image: in the xml it is named “<g:price>” which is different than the other ones (no “g:”)

2/ how to exclude product types, like f.ex. I just want to show products of brand2

3/ how to not show entries that have no content

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.