(计算($ list)1或2项

时间:2013-01-18 22:26:23

标签: php joomla

脚本指示如果有1或2个脚本帖子加倍的部分。我只想要(如果有1或2篇文章)它只显示1或2篇文章

<?php
    defined('_JEXEC') or die;
    $count = 0;
    if (count($list)%3!=0) {
        $list = array_merge($list, array_slice($list, 0, 3-count($list)%3));
    }
    if (count($list)%2!=0) {
        $list = array_merge($list, array_slice($list, 0, 2-count($list)%2));
    }
    if (count($list)%1!=0) {
        $list = array_merge($list, array_slice($list, 0, 1-count($list)%1));
    }
?>

<?php JLoader::register('fieldattach', 'components/com_fieldsattach/helpers/fieldattach.php'); ?>

<div id="slides">
    <div class="slides_container">

        <div class='slide'>
            <?php foreach ($list as $item) :
                if (($count>0) and ($count%3==0)): ?>
                    </div>
                    <div class="slide">
                <?php endif; ?>

                <li class="categories">
                    <a href="<?php echo $item->link; ?>">
                        <?php echo fieldattach::getImg($item->id, 6); ?>
                        <h4><?php echo $item->title; ?></h4>
                    </a>
                </li>

            <?php $count++; endforeach; ?>
        </div>
    </div>
</div>

0 个答案:

没有答案