Re: Filtering by category from a detail page

4 posts by 3 authors in: Forums > CMS Builder
Last Post: February 8, 2016   (RSS)

By ross - February 4, 2016

Hi Jeff

I am not sure if Jerry has seen this post or not.  Could you post more details about what you are trying to setup?

The form code looks ok to me at first glance.

Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By JeffC - February 4, 2016

Hi Ross

I'm trying to do two things. The first is to show just the children of a parent category. The line below achieves this:

<?php if($categoryRecord['parentNum'] == $page['num']): ?>

I'm then trying to set up a form that enables the website user to further filter the results based on which tag they have: kitchen, bedroom or bathroom

Jeff

Hi Jeff,

I think something like this should work:

<form method="POST" action="<?php echo $_SERVER['PHP_SELF'] ?>">
  <select name = "roomtag_match" > 
    <option value="">Please Choose a Category</option>
    <?php foreach (getListOptions('iw_pages', 'roomtag') as $value => $label): ?> 
      <option value="<?php echo $value;?>" <?php selectedIf($value, @$_REQUEST['roomtag']);?>><?php echo $label; ?></option> 
    <?php endforeach ?> 
  </select> 
  <input type="submit" name="submit" value="Search" >
</form>


<section id="pinBoot"> 
  <?php foreach ($iw_pagesRecords as $categoryRecord): ?>
    <?php if($categoryRecord['parentNum'] == $page['num'] && ( !@$_REQUEST['roomtag_match'] || $_REQUEST['roomtag_match'] == $categoryRecord['roomtag'] ) ): ?>
      <article class="white-panel">
        <?php foreach ($categoryRecord['photos'] as $index => $upload): ?> 
          <img src="<?php echo $upload['thumbUrlPath2'] ?>" width="100%" title="<?php echo htmlspecialchars($upload['info1']) ?>" alt="<?php echo htmlspecialchars($upload['info1']) ?>" />
          <?php break; ?>
        <?php endforeach ?>
        <h4><?php echo htmlencode($categoryRecord['name']) ?></h4>
        <p><?php echo htmlencode($categoryRecord['short_description']) ?></p>
        <a href="<?php echo $categoryRecord['_link'] ?>">Read more…</a>
      </article>
    <?php endif ?>
  <?php endforeach; ?>
</section>

I've added the following new line:

<?php if($categoryRecord['parentNum'] == $page['num'] && ( !@$_REQUEST['roomtag_match'] || $_REQUEST['roomtag_match'] == $categoryRecord['roomtag'] ) ): ?>

So this if statement checks that the category matches the page num, if no roomtag match has been selected, all the sub category records will be shown, if a room tag match has been selected, only sub category records with the matching tag will be displayed.

This is demo code, so you might have to make a few changes to get it working. 

Cheers,

Greg

Greg Thomas







PHP Programmer - interactivetools.com