Where or {continue} ?
6 posts by 2 authors in: Forums > CMS Builder
Last Post: March 2, 2010 (RSS)
By Perchpole - March 1, 2010
Although I don't have much php experience I think I'm canny enough to work out most things to fulfil a particular requirement. In recent days, however,I've encountered a number of issues where my usual clumsy approach would benefit from a bit of finesse!
Here's a typical example...
Parent Category
- Child 1
- Child 2
- Child 3
I need to show all the items of a parent category and its child categories in one list. I think I can do this in either of two ways...
First by using a "where" argument - to list only those articles found in the parent and/or child categories.
Second, by use of a {continue} construct in the list's foreach loop - to filter out unwanted entries.
Could someone please show me a neat way of doing this?
Thanks
Perch
Re: [Perchpole] Where or {continue} ?
By Chris - March 2, 2010
Can this be solved with "rootCategoryNum"?
$numOfParentCategory = 123;
list($categoryRecords, $selectedCategory) = getCategories(array(
'tableName' => 'category',
'rootCategoryNum' => $numOfParentCategory,
));
Does that help? Please let me know if you have any questions.
Chris
Re: [chris] Where or {continue} ?
By Perchpole - March 2, 2010
Thanks for your note. The short answer is, Yes, it could work but I'd prefer to use a solution that could be applied, automatically, to every eventuality - rather than something that needs to be tailored to suit every instance.
I thought there would be a cunning way to use some of the preset arguments to arrive at a solution!
:0)
Perch
Re: [Perchpole] Where or {continue} ?
By Chris - March 2, 2010
We can generalize the above solution if we can figure out the "num" of the parent category to display.
How does the page that's displaying this list of categories know which parent category it wants to display? Is the num passed in the query string or do you need to search some fields to determine which category?
If you can give me a specific example of how you want this to work, I can show you how to generalize it.
Chris
Re: [chris] Where or {continue} ?
By Perchpole - March 2, 2010
The number would come direct from the category num - which presumably would be at the end of the URL.
:o)
Perch
Re: [Perchpole] Where or {continue} ?
By Chris - March 2, 2010
Does this solve the problem then?
$numOfParentCategory = getNumberFromEndOfUrl();
list($categoryRecords, $selectedCategory) = getCategories(array(
'tableName' => 'category',
'rootCategoryNum' => $numOfParentCategory,
));
Please let me know if you have any questions.
Chris