Show Articles with it's Category instead of a separate list

4 posts by 2 authors in: Forums > CMS Builder
Last Post: September 27, 2012   (RSS)

By ScottL - September 26, 2012 - edited: September 26, 2012

I have an editor setup to select a Category related to the Article. When displayed, it shows a list of categories, then Articles. Click on a category and it shows only that category. Is there a way to show Articles with it's category? (see attached).

Here's what I have for code:
<table width="70%" border="0" cellspacing="0" cellpadding="10">
<tr>
<th scope="col"> <ul>
<div align="left"><span class="articles">
<?php foreach ($piston_categoriesRecords as $categoryRecord): ?>
<?php echo $categoryRecord['_listItemStart'] ?>

<?php if ($categoryRecord['_isSelected']): ?>
<b>
<?php endif ?>
<a href="?category=<?php echo $categoryRecord['num'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php if ($categoryRecord['_isSelected']): ?>
</b>
<?php endif ?>

<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach ?>
</span> </div>
</ul> </th>

</tr>
</table>
<table width="85%" border="0" class="articles2" align="center" cellpadding="0" cellspacing="0">
<tr>
<th scope="col"><p align="left">
<?php foreach ($light_aircraft_projectsRecords as $record): ?>
<span class="style3"><?php echo $record['title'] ?></span> – <a href="<?php echo $record['_link'] ?>"><em>Read more</em></a><br/>

</p>
<div align="left">
<?php endforeach ?>
</div>
<a href="light-aircraft-projects.php"></a></th>
</tr>
</table>
<br>
<a href="light-aircraft-projects.php"><u>Show All Recent Piston Projects</u></a>

Re: [ScottL] Show Articles with it's Category instead of a separate list

By gregThomas - September 26, 2012

Hi,

So you have a section of articles and each one has has a category which it gets from a categories section? Are these linked using the list field type as described in this article?

http://www.interactivetools.com/kb/article.php?Populate-a-list-field-from-another-section-15

If this is how you have your system set up then you should be able to get a articles category by doing something like this:

<?php
//I'm assuming that $light_aircraft_projectsRecords contains the articles array and has a categories field
foreach ($light_aircraft_projectsRecords as $record): ?>

<span class="style3"><?php echo $record['title'] ?></span> – <a href="<?php echo $record['_link'] ?>">
Category: <?php echo $record['fieldGoesHere:labels']; ?>
<em>Read more</em></a><br/>

</p>
<div align="left">
<?php endforeach ?>


You'll need to replace fieldGoesHere with the name of the field that contains the category list.

Let me know if this doesn't work.

Thanks
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] Show Articles with it's Category instead of a separate list

By ScottL - September 27, 2012

Sorry. That's not working. Yes, I have categories set up and each article will be assigned to a category. Categories are linked with list field type.

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php

require_once "/home/content/41/5724841/html/cmsAdmin/lib/viewer_functions.php";

list($piston_categoriesRecords, $selectedCategory) = getCategories(array(
'tableName' => 'piston_categories',
));

list($light_aircraft_projectsRecords, $light_aircraft_projectsMetaData) = getRecords(array(
'tableName' => 'light_aircraft_projects',
));

?>




I don't see how your suggestion will sort the categories like this:

Category 1
story 1 link
story 2 link
etc.

Catgeory 2
story 1 link
story 2 link
etc.

Category 3
story 1 link
story 2 link
etc.

Thanks.