Displaying list items by category

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

By CommonSenseDesign - April 3, 2013

I have section of a site where my client can create categories, such as "Window Treatments" and "Painted Furniture". They can then go to a different section of CMSB and create a listing that goes into one of the categories they created. These categories appear in CMSB as a dropdown menu that is populated by using "Get options from database (advanced)".

I've produced a list page that shows all of the individual records, but I'd like there to be a page that lists all the categories. The items on the list would link to a listings page that only shows the items within the chosen category.

Here's the listing page I have now, which shows everything that has been input: http://kathiejordandesign.com.previewdns.com/store.php. However, I'd like this to appear first - http://kathiejordandesign.com.previewdns.com/storeCategories.php - and the items should link to a page that shows only the selected category. Here's what a typical details page looks like: http://kathiejordandesign.com.previewdns.com/storeDetails.php?Lady-of-Shalott-1.

Thanks!

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

By CommonSenseDesign - April 4, 2013

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