Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
Question concerning Chris' subcategory tutorial

 

 


Hansaardappel
User

Mar 13, 2010, 4:30 PM

Post #1 of 6 (4075 views)
Shortcut
Question concerning Chris' subcategory tutorial Can't Post

First off all, thanks for creating the tutorial, it has been a great help! Now my question. How do I display the articles of only one category? If I take the tutorial as an example, how do I only display the Dog Articles. So no categories or other articles, just the articles within the category "Dog".

Thanks alot!

Hansie


Hansaardappel
User

Mar 15, 2010, 11:34 AM

Post #2 of 6 (4053 views)
Shortcut
Re: [Hansaardappel] Question concerning Chris' subcategory tutorial [In reply to] Can't Post

bump...


Chris
Staff


Mar 15, 2010, 4:32 PM

Post #3 of 6 (4047 views)
Shortcut
Re: [Hansaardappel] Question concerning Chris' subcategory tutorial [In reply to] Can't Post

Hi Hansaardappel,

You can do this by generating a List Viewer for your Articles section. You have two options as to how to display only articles in the Dogs category:

(Let's assume that your Dogs category has a num of "1".)

1. Link to your List Viewer with ?category=1

This will cause the getRecords() call to filter articles which belong to other categories.

2. Hard-code the List Viewer to filter articles with a "where" clause. Do to this, change your getRecords() call to:


Code
  list($articlesRecords, $articlesMetaData) = getRecords(array( 
'tableName' => 'articles',
'where' => 'category = 1',
));


Do these solutions solve your problem?

Please let me know if you have any questions.
Chris


Hansaardappel
User

Mar 18, 2010, 10:26 AM

Post #4 of 6 (4024 views)
Shortcut
Re: [chris] Question concerning Chris' subcategory tutorial [In reply to] Can't Post

That worked great Chris, thanks. I've got a new problem though Mad

I'm currently working on adding articles to multiple categories, I changed the list to multi value and chose the appropriate categories for my articles. Displaying articles that only belong to a single category still works fine, but I'm having some problems with articles that belong to multiple categories. There's this one article, that belongs to category "Tournament Results" (Parent category (num=1)), "Indian Wells" (sub category of Tournament Results (num=2)) and to "Roger Federer" (Parent category (num=3)). What I want to do is to only display the articles within category "Roger Federer".

My code:

list($categoriesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'categories',
'categoryFormat' => 'onelevel',
));

list($articlesRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
'perPage' => '5',
'where' => 'category = 3',
));

// Display code

<?php foreach ($articlesRecords as $record): ?>
<?php echo $record['content'] ?><br/>
<?php endforeach; ?>

<?php if (!$articlesRecords): ?>
No records were found!<br/><br/>
<?php endif ?>

Other articles in the category are being displayed fine, but not this specific article. When I remove the article from the other categories, so that the category "Roger Federer" is the only one it belongs to, it DOES get displayed.

What am I doing wrong?


Chris
Staff


Mar 18, 2010, 1:49 PM

Post #5 of 6 (4019 views)
Shortcut
Re: [Hansaardappel] Question concerning Chris' subcategory tutorial [In reply to] Can't Post

Hi Hansaardappel,

CMS Builder stores multi-value list fields as a tab-separated list. It also puts a tab on the front and back of the list for easy searching.

For example, your article's category field will be:

tab 1 tab 2 tab 3 tab

...which is represented as:

"\t1\t2\t3\t"

Finding all the articles which belong to category 3 simply involves looking for category fields which contain "\t3\t". To do that, change your 'where' line to:


Code
'where' => "category LIKE '%\t3\t%'",


I hope this helps. Please let me know if you have any questions.
Chris


Hansaardappel
User

Mar 18, 2010, 4:44 PM

Post #6 of 6 (4013 views)
Shortcut
Re: [chris] Question concerning Chris' subcategory tutorial [In reply to] Can't Post

You are my hero Wink Thanks a lot!