Excluding Specific Categories

9 posts by 2 authors in: Forums > CMS Builder
Last Post: June 2, 2017   (RSS)

By osga - May 9, 2017

Is there a way to exclude a specific category from the main list/news feed?

we're trying to avoid the doubling of headlines that appear on our homepage...

thanks in advance!

By Deborah - May 11, 2017 - edited: May 14, 2017

Hi, osga.

If the category list options are set up within the News section editor, I use something like the following...

list($newsRecords, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where'    => ' category NOT LIKE "%YourCategoryName%" ',

Replace YourCategoryName with the name of your desired category.

~ Deborah

By osga - May 15, 2017 - edited: May 15, 2017

thank you for the response... how would we implement this on the page...?

page included...


index_newsfeed.html 2K

By Deborah - May 15, 2017

Osga, I believe the only change you'll need to make is to add the 'where' clause as shown here:

  // load records
  list($articlesRecords, $articlesMetaData) = getRecords(array(
    'tableName'   => 'articles',
    'where'       => ' category NOT LIKE "%YourCategoryName%" ',
    'limit'       => '9',
    'loadUploads' => '0',
    'orderBy'     =>  'date DESC',

You'll need to edit YourCategoryName to match the actual category to be excluded.

~ Deborah

By osga - May 16, 2017

generates this error

"MySQL Error: Unknown column 'category' in 'where clause'"

(new page for code attached....)

By osga - May 25, 2017

Hi Deborah... we finally got this work with a little playing around, Note the "CategoryNum" as opposed to the suggested "category" in the statement (make a mental note of that)...

now the question is: Do you know the syntax for excluding more than 1 category?

  'where'       => ' categoryNum NOT LIKE "9" ',

thanks for all ur help so far!

By Deborah - June 2, 2017

Osga, try this:

 'where' => ' categoryNum NOT LIKE "9" AND categoryNum NOT LIKE "5"',

~ Deborah

By osga - June 2, 2017

that worked like a charm Deborah, Thank You!