Product listing: check two category fields

3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 9, 2013   (RSS)

By jjem - July 8, 2013

Hi,

I do have a listing of musical works. On a one page layout, it selects works from different categories ID and put them under subtitles.

For now this is my code (which is working) but I need it to check "categorie2" field each time as well because some works appear in 2 different categories (I made two categories fields in my "works" table).

Thanks for your help

Jeremy

<!-- Musique cordes -->
         <section id="oeuvrescordes">
          <div class="page-header">
          <h3>Cordes</h3>
          </div>
          <?php foreach ($oeuvresRecords as $record): ?>
          <?php if ($record['categorie'] == '12'): ?>
          <h4><?php echo $record['titre'] ?></h4>
          <p><?php echo $record['formation'] ?></p>
          <p><a href="<?php echo $record['_link'] ?>">Détails</a></p>
          <?PHP endif ?>
          <?php endforeach; ?>
          </section>
 <!--section -->
<!-- Musique vents -->
         <section id="oeuvresvents">
          <div class="page-header">
          <h3>Vents</h3>
          </div>
          <?php foreach ($oeuvresRecords as $record): ?>
          <?php if ($record['categorie'] == '13'): ?>
          <h4><?php echo $record['titre'] ?></h4>
          <p><?php echo $record['formation'] ?></p>
          <p><a href="<?php echo $record['_link'] ?>">Détails</a></p>
          <?PHP endif ?>
          <?php endforeach; ?>
          </section>
 <!--section -->
<!-- Musique vents -->
         <section id="oeuvresmixte">
          <div class="page-header">
          <h3>Instruments mixtes</h3>
          </div>
          <?php foreach ($oeuvresRecords as $record): ?>
          <?php if ($record['categorie'] == '14'): ?>
          <h4><?php echo $record['titre'] ?></h4>
          <p><?php echo $record['formation'] ?></p>
          <p><a href="<?php echo $record['_link'] ?>">Détails</a></p>
          <?PHP endif ?>
          <?php endforeach; ?>
          </section>
 <!--section -->

By gregThomas - July 8, 2013

Hi Jeremy,

So the item needs to be displayed if it appears in the categorie OR categorie2?

What about doing adding an or statement to your if statement to check if the item appears in category2 as well:

<?php foreach ($oeuvresRecords as $record): ?>
  <?php if ($record['categorie'] == '12' || $record['categorie2'] == '12'): ?>
    <h4><?php echo $record['titre'] ?></h4>
    <p><?php echo $record['formation'] ?></p>
    <p><a href="<?php echo $record['_link'] ?>">Détails</a></p>
  <?php endif ?>
<?php endforeach; ?>

So if the item has a category of 12 or a category2 of 12, then the item will be displayed.

Let me know if you have any questions.

Thanks

Greg

Greg Thomas







PHP Programmer - interactivetools.com