Hide last record in the "Other News" section

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 12, 2011   (RSS)

By Hansaardappel - August 11, 2011

Hi Guys,

I have a small problem with my index page. Today I changed the setup of my index page, making a small preview + image (kinda like a headline) for my last record and then showing the list of other news. Despite my lack of PHP knowledge, I managed to create a summary, but the one problem I have now is the fact that the last record also appears in the other news section.

So let's say my last 3 articles are called
1. Netherlands (last article and therefore the headline)
2. Belgium
3. Australia

My question now is, how do I remove Netherlands from the other news section?

Here's my code at the top of the page:

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

list($articlesRecords, $articlesMetaData) = getRecords(array(
'tableName' => 'articles',
$exclude= 2,
));

list($categoryRecords,$categoryMetaData) = getRecords(array(
'tableName' => 'categories',
));

$numToName=array();

foreach($categoryRecords as $record){
$numToName[$record['num']]=$record['name'];
}

foreach($articlesRecords as $headlines){
};

list($headlinesRecords,$headlinesMetaData) = getRecords(array(
'tableName' => 'articles',
'limit' => '1',
));


My code in the body of my page:

<?PHP
function maxWords($textOrHtml, $maxWords) {
$text = strip_tags($textOrHtml);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);

return $output;
}
?>
<?php foreach ($categoriesRecords as $categoryRecord): ?>
<?php endforeach ?>

<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
<?php foreach ($headlinesRecords as $record): ?>
<?php echo $numToName[$record['category']] ?>:
<?php echo $record['title'] ?><p></p>
<?php foreach ($record['images'] as $upload): ?>
<img src="<?php echo $upload['urlPath'] ?>" />

</h2>
<?PHP echo maxWords($record['content'], 100);
?>
<?php endforeach; ?>

<?php if (!$articlesRecords): ?>
No records were found!<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->
...<p></p>
<a href="<?php echo $record['_link'] ?>">Read More &raquo;</a><p></p>
<?php endforeach ?>
<h2>Other News</h2><p></p>
<?php foreach ($articlesRecords as $record): ?>
<a href="<?php echo $record['_link'] ?>">
<?php echo $record['title'] ?></a><p></p>
<?php endforeach ?>


Thanks!

Re: [Hansaardappel] Hide last record in the "Other News" section

By Jason - August 12, 2011

Hi,

Glad to hear you got everything working properly. Please let us know if you run into any other problems.

Thanks
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/