Having menu nav subs limit the number to display

5 posts by 2 authors in: Forums > CMS Builder
Last Post: December 12, 2009   (RSS)

I have this list page displaying only the 10 latest "articles"

http://65.99.232.147/articles/articles.php

What I need to do is to get the sub navigation also only display the last 10 articles as well.

How to do this? Here is my article nav code:

<li> <a href="/articles/articles.php">Articles</a> <ul>
<?php
list($categoryRecords, $selectedCategory) = getCategories(array(
'tableName' => 'articles',
'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()
'categoryFormat' => 'showall', // showall, onelevel, twolevel
));
?>
<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php if ($categoryRecord['url']) { $categoryRecord['_link'] = $categoryRecord['url']; } ?>


<?php echo $categoryRecord['_listItemStart'] ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>


</ul>
</li>
<!-- <li><span class="qmdivider qmdividery" ></span></li>-->

Re: [drewh01] Having menu nav subs limit the number to display

By Chris - December 10, 2009

Hi drewh01,

I'm not sure I understand what you mean by sub navigation. Can you please explain what the problem is exactly, preferably with an example showcasing the issue?
All the best,
Chris

Re: [drewh01] Having menu nav subs limit the number to display

By Chris - December 11, 2009

Hi drewh01,

If you add these two lines in red, your foreach will stop after displaying ten records:

<?php $count = 0; ?>
<?php foreach ($categoryRecords as $categoryRecord): ?>
<?php $count++; if ($count > 10) { break; } ?>
<?php if ($categoryRecord['url']) { $categoryRecord['_link'] = $categoryRecord['url']; } ?>
<?php echo $categoryRecord['_listItemStart'] ?>
<a href="<?php echo $categoryRecord['_link'] ?>"><?php echo $categoryRecord['name'] ?></a>
<?php echo $categoryRecord['_listItemEnd'] ?>
<?php endforeach; ?>


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

Re: [chris] Having menu nav subs limit the number to display

Very helpful, thanks!