I need a code that pulls out the listings count for a product in order to have them in the navigation. I am trying to get the product and listing number in the navigation (if there is any), but I don't want to display something if the listings count is equals to 0.
Here follows my code:
<?php if($listingsCount = getListingsCount(0,0,2,2,1,86) > 0): ?>
<a href="">Bakery</a>
<?php echo $listingsCount['totalRecords'] ?>.
<?php else: ?>
It should be
if ( ($listingsCount = getListingsCount(0,0,2,2,1,86)) > 0)
In this case you the assignment is done first and is then compared to 0
. So $listingCount
contains the real count.
The way you did it, the comparison is done first and the return value (true/false
) is assigned to $listingCount
.
Nevertheless. If you never reach the else
-part, maybe something in your method getListingsCount()
is broken.
Try this:
<?php if (($listingsCount = getListingsCount(0,0,2,2,1,86)) > 0) { ?>
<a href="">Bakery</a>
<?php echo $listingsCount['totalRecords']; ?>
<?php } else { ?>
Other text
<?php }?>
Thanks guys for your answers. managed to get it working with this...
<?php
$listingsCount = getListingsCount(0,0,2,2,1,86);
if($listingsCount['totalRecords'] > 0):
?>
<dd>
<a href="">Bakery</a>
[<?php echo $listingsCount['totalRecords'] ?>]
</dd>
<?php endif; ?>