0

I have following codes:

<?php foreach ($list as $item) : ?>
    <li<?php if ($id == $item->id && in_array($view, array('category', 'categories')) && $option == 'com_content') echo ' class="active"'; ?>>
        <?php $levelup = $item->level - $startLevel - 1; ?>
        <a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($item->id)); ?>">
        <?php echo $item->title; ?>
            <?php if ($params->get('numitems')) : ?>
                (<?php echo $item->numitems; ?>)
            <?php endif; ?>
        </a>

Could anyone tell how to random the title? And control the showing numbers?

5
  • Do you mean shuffle($list)? What are you currently seeing as output? What output do you want? Nov 11, 2020 at 7:15
  • Thanks for your help. I don't know where I should add shuffle($list) or rand(); For example, I have 4items in this category: item1, item2, item3, item4 Now, output: item1, item2, item3, item4 I want to randomly output only 2 items, such as: item2, item4
    – zhang
    Nov 12, 2020 at 9:22
  • Before the foreach() seems sensible. Nov 12, 2020 at 9:23
  • Thanks for your help. I don't know where I should add shuffle($list) or rand(); For example, I have 4items in this category: item1, item2, item3, item4 Now, output: item1, item2, item3, item4 I want to randomly output only 2 items, such as: item2, item4
    – zhang
    Nov 12, 2020 at 9:27
  • <?php shuffle($list); foreach ($list as $item) : ?>? I don't see the purpose of declaring $levelup. Nov 12, 2020 at 10:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.