mercredi 26 juillet 2017

Return the number of loops before a loop

I'm trying to return the number of products in a loop and output this before the loop. The below always returns 0, so is there a way that I can delay outputting this until after it has finished the loop?

if( $post_objects ):
$prodcount = 0;
?>

<h1>There are <?php echo $prodcount ?> items</h2>

<?php foreach( $post_objects as $post_object): ?>

<p>something</p>

<?php $prodcount++ ?>

<?php endforeach; ?>

<?php endif; ?>

Aucun commentaire:

Enregistrer un commentaire