Hi all
I have a XML file holding all my content - a list of hotels which is displayed with PHP as shown below adding a class=“last” to every third element, works good.
My problem now, I need to add another class of class=“featured” and extra markup <span>featured</span> to a unique hotel name(s) and maybe sometimes at random.
The featured class might also be needed on the third element which already has the class=“last”.
How do I achieve this with the code below?
My existing code:
<?php $hotels = simplexml_load_file("hotel_listing.xml"); ?>
<?php $i=1; foreach ($hotels->hotel as $hotel): ?>
<?php $clss= ($i % 3 == 0)? 'class="last"':'' ?>
<div <?php echo $clss ?> >
<img src="images/<? echo $hotel->img->name ?>">
<h3><?php echo $hotel->name ?></h3>
<p><?php echo $hotel->description ?></p>
<p><b>Rating:</b> <?php echo $hotel->star ?></p>
</div>
<? $i++;?>
<? endforeach ?>
I would also like to order the hotels using some to sort of xpath.
I did try the below nothing happened…
<?php $hotels->xpath("star"); ?>
Any feedback much appreciated
Barry