Re: Filtering by category from a detail page

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

By JeffC - February 2, 2016

In response to: [url "http://www.interactivetools.com/forum/forum-posts.php?postNum=2236729#post2236729"]Filtering by category from a detail page[/url], ...

Hi Jerry

I am trying to follow your instructions on the above thread and the cmsbcookbook, but I am unable to get things to work as desired. When the search form is submitted the page refreshes but the results do not change on the list page. No errors are recorded in the error log.

I am guessing that there could be a couple of issues:

1. Your code is for a detail page. I am using this code with a category menu. (When using a category menu I am not really sure how to differentiate between what is a 'list page' and what is a 'detail page'.)

2. I am guessing that maybe that <form>… </form> needs to envelope <section id="pinboot">… </section>

For your reference my roomtags are "Kitchen, Bathroom, Bedroom". I would like the default view of the page to be a list of pages where the $categoryRecord['parentNum'] == $page['num'] (this part of the code works). I would then like the website user to be able to further filter this results where:

$categoryRecord['parentNum'] == $page['num'] AND roomtag=kitchen

or

$categoryRecord['parentNum'] == $page['num'] AND roomtag=bathroom

or

$categoryRecord['parentNum'] == $page['num'] AND roomtag=bedroom

Here is my code:

<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']): ?>


<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>

Thanks

Jeff

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 gregThomas - February 8, 2016

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