1

Good evening!

Being a total PHP-n00b I'm asking here hoping some clever brain out there can help me out. This is the case:

<?php if(wpsc_product_count() == 3 ) :?>
<div class="productseparator"></div>     
<?php endif ; ?>

Now, what I want out of this is the following: If wpsc_product_count matches 3, 6, 9, 12, 15, 18, 21, 24, 27 or 30 - I would like it to print nothing at all. Every other value should print the .productseparator DIV.

Thanks a million in advance!

Eirik
  • 31
  • 3

4 Answers4

3

Use this function:

<?php if(wpsc_product_count() % 3 != 0) :?>
<div class="productseparator"></div>     
<?php endif ; ?>
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
thetaiko
  • 7,816
  • 2
  • 33
  • 49
1

Try this

    <?php
    echo (wpsc_product_count() % 3 == 0) ? '' : '<div class="productseparator"></div>';
    ?>
secretformula
  • 6,414
  • 3
  • 33
  • 56
0
if (!in_array(wpsc_product_count(), array(3,6,9,12,15,18,21,24,27,30)) {
   echo '<div class="productseparator">';
}

relevant man page here.

Marc B
  • 356,200
  • 43
  • 426
  • 500
0

One approach:

<?php
    $cnt = wpsc_product_count();
    if ($cnt > 0 && $cnt <= 30 && % 3 > 0) {
        print '<div class="productseparator"></div>';
    }
?>

using the '%' operator will give you the remainder of a/b.

Doug Kress
  • 3,537
  • 1
  • 13
  • 19