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 > brand2 > brand3 > 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 $data->link ."<br> ";
echo "</div>";
echo "</div>";
}
?>
but it gives me this issue on how to see a button with link to the website opening in a new tab. So not to have the link visible, but have it behind a button.
2
Answers
Here's the answer: replace
by
If I understood correctly – you wish to have a button to take the user to the relevant URL rather than display the actual URL on the page?! If so then you could include an inline hyperlink that contains a simple button that displays some text or other.
Example of how the HTML might look