show similar children links from Category Section at foot of page

15 posts by 3 authors in: Forums > CMS Builder
Last Post: February 9, 2010   (RSS)

Re: [benedict] show similar children links from Category Section at foot of page

Hi guys,

Any word on this?

Re: [benedict] show similar children links from Category Section at foot of page

By ross - December 8, 2009

Hi there.

Thanks for posting :). Just a point of reference, we are closed on the weekends so we won't get back to you on Sundays. Of course, we should have been in touch the next day though. There can be a bit of a backlog on Mondays.

Now, having said that, you should be able to get your other listings to show up. Would you mind attaching a copy of your page for me to have a look at? If you could, actually attach it as a file, pasting code as the reply is harder to read :).

Thanks!
-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

Re: [ross] show similar children links from Category Section at foot of page

Hi Ross,

Sure, here's the page for your perusal.

Cheers,

Benedict
Attachments:

archive_001.zip 9K

Re: [benedict] show similar children links from Category Section at foot of page

Hi Ross,

How did you go with this?

Cheers,

Benedict

Re: [benedict] show similar children links from Category Section at foot of page

By Chris - December 10, 2009

Hi Benedict,

Whoa, that's an interesting one. How about listing all the articles which belong to a category under the article's category's parent category (phew.)

Maybe something like this would do the trick?

// load the selected news record
list($newsRecords,) = getRecords(array(
'tableName' => 'news',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$newsRecord = @$newsRecords[0]; // get first record

// load the category record for this news record
list($categories,) = getRecords(array(
'tableName' => 'conditions_treatments',
'where' => "num = '" . $newsRecord['conditions_treatments'] . "'",
));
$category = @$categories[0];

// load all categories which are children of the news record's category
list($relatedCategoryRecords,) = getCategories(array(
'tableName' => 'conditions_treatments',
'rootCategoryNum' => $category['parentNum'],
));

// list news records which belong to related categories (except the selected news record)
$relatedNews = array();
$relatedCategoryNumsCSV = implode(',', array_pluck('num', $relatedCategoryRecords));
if ($relatedCategoryNumsCSV) {
list($relatedNews,) = getRecords(array(
'tableName' => 'news',
'where' => "conditions_treatments IN ($relatedCategoryNumsCSV) AND num != '" . $newsRecord['num'] . "'",
));
}


I hope this helps! Please let me know if you have any questions.
All the best,
Chris

Re: [chris] show similar children links from Category Section at foot of page

Hi Chris,

Not quite - I notice in your code you're relating news stories to conditions_treatments. These are unrelated in the site.

It is only conditions_treatments that I need to show related conditions for at the bottom of the page (i.e. other children under the same parent) so hopefully this makes it a bit simpler to acheive (?).

Re: [benedict] show similar children links from Category Section at foot of page

By Chris - December 10, 2009

Hi Benedict,

Ahh, yes. That will makes things simpler. Something like this then?

// load the selected category record
list($categories,) = getRecords(array(
'tableName' => 'conditions_treatments',
'where' => whereRecordNumberInUrl(1),
));
$category = @$categories[0];

// load all categories which are children of this category's parent
list($relatedCategoryRecords,) = getCategories(array(
'tableName' => 'conditions_treatments',
'rootCategoryNum' => $category['parentNum'],
));

All the best,
Chris

Re: [chris] show similar children links from Category Section at foot of page

Better, but still not quite. This time it is not throwing any errors, but it is listing every single category, both parent and child.

I'm using this to pull the records:


<h2>Related Items</h2>
<ul>
<?php foreach ($relatedCategoryRecords as $record): ?>
<li><a href="<?php echo $record['_link'] ?>"><?php echo $record['name'] ?></a></li>
<?php endforeach; ?>
</ul>


Is that right? I've attache my page again, just in case.

Re: [benedict] show similar children links from Category Section at foot of page

By Chris - December 11, 2009

Hi Benedict,

You can skip the current category with the following line right after the foreach:

<?php if ($category['num'] == $record['num']) { continue; } ?>

Do you have an example I can check out to see the problem? Also, I think you forgot to post your page.
All the best,
Chris