Displaying list items by category

5 posts by 2 authors in: Forums > CMS Builder
Last Post: April 5, 2013   (RSS)

By gregThomas - April 4, 2013

Hi Nigel,

I think you only have to make a few amendments to your store page to get the filtering working, I've made these changes on line 59 of store.php:

  $where = '';
  $number = getLastNumberInUrl(0);

  if($number > 0){
    $where = "name_of_list_field = $number";
  }

  list($catalogueRecords, $catalogueMetaData) = getRecords(array(
    'tableName'   => 'catalogue',
    'perPage'     => '10',
    'where'       => $where,
    'loadUploads' => true,
    'allowSearch' => false,
    'orderBy'     => 'dragSortOrder DESC ',
  ));

The only change I think you'll need to make is set name_of_list_field to field name of the list field that is populated by using "Get options from database (advanced)".

So the getLastNumberInUrl function will retrieve the last number in the URL if one is set. If a number exists, then a where string is created will filter out only records with the specific list field.

Finally this where string is added to the getRecords function.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

Thanks, Greg. This works really well. http://kathiejordandesign.com.previewdns.com/storeCategories.php

Please can you tell me if it's possible to do the following, too. Not all of the categories shown on this page (http://kathiejordandesign.com.previewdns.com/storeCategories.php) have items added to them; e.g. Gurgle Pots & Guggle Jugs doesn't have any products yet (http://kathiejordandesign.com.previewdns.com/store.php?Gurgle-Pots-Guggle-Jugs-15). Is it possible to either hide any categories on the main index page if they don't have any items? If not, how about putting the number of items in brackets after the category's name in the list; e.g. Gurgle Pots & Guggle Jugs (0); Oil Paintings by Local Artists (2). Hiding the empty categories would be preferable.

By gregThomas - April 5, 2013

What about adding a 'hidden' check box to the category section, and hiding categories that you havn't added items too yet?

If you create a checkbox called 'hidden' in the category section, the getRecords function will automatically not retrieve records with it checked. 

If you wanted to add a counter for the number of records, you could implement the code from this post: http://www.interactivetools.com/forum/forum-posts.php?postNum=2229899#post2229899

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

The hidden checkbox is so obvious, I don't know why I didn't think of it! Thanks, Greg.