douyan1903 2013-03-19 07:47
浏览 58
已采纳

取第一个php foreach的结果并继续

This is a very difficult question to ask but, lets try. I am using this module for joomla i need tocreate an overide for it so that it takes the first result of

<?php foreach( $pages as $key => $list ): ?>

and places it in its own div and carries on with the statement. Please ask if any other information is needed here's the entire code for the override:

<?php
/**
 * @package     mod_bt_contentslider - BT ContentSlider Module
 * @version     1.4
 * @created     Oct 2011

 * @author      BowThemes
 * @email       support@bowthems.com
 * @website     http://bowthemes.com
 * @support     Forum - http://bowthemes.com/forum/
 * @copyright   Copyright (C) 2012 Bowthemes. All rights reserved.
 * @license     http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
 *
 */
// no direct access
defined('_JEXEC') or die('Restricted access');

if($modal){JHTML::_('behavior.modal');}
$document = JFactory::getDocument();

if(count($list)>0){?>
<div id="btcontentslider<?php echo $module->id; ?>" style="display:none;" class="span4 bt-cs<?php echo $moduleclass_sfx? ' bt-cs'.$params->get('moduleclass_sfx'):'';?>">
  <!--CONTENT-->
    <div class="slides_container" style="width:<?php echo $moduleWidth.";".$add_style;?>">
    <?php foreach( $pages as $key => $list ): ?>
        <div class="slide" style="width:100%;">
        <?php foreach( $list as $i => $row ): ?>
            <ul class="bt-row <?php if($i==0) echo 'bt-row-first'; else if($i==count($list)-1) echo 'bt-row-last' ?>"  style="width:100%" >
                <li class="bt-inner">
                <?php if( $row->thumbnail && $align_image != "center"): ?>
                    <a target="<?php echo $openTarget; ?>" class="bt-image-link<?php echo $modal? ' modal':''?>" title="<?php echo $row->title;?>" href="<?php echo $modal?$row->mainImage:$row->link;?>">
                      <img <?php echo $imgClass ?>  src="<?php echo $row->thumbnail; ?>" alt="<?php echo $row->title?>"  style="width:<?php echo $thumbWidth ;?>px; float:<?php echo $align_image;?>;margin-<?php echo $align_image=="left"? "right":"left";?>:5px" title="<?php echo $row->title?>" />
                    </a> 
                <?php endif; ?>

                    <?php if( $showTitle ): ?>
                    <a class="bt-title" target="<?php echo $openTarget; ?>"
                        title="<?php echo $row->title; ?>"
                        href="<?php echo $row->link;?>"> <?php echo $row->title_cut; ?> </a><br />
                    <?php endif; ?>
                    <?php if( $row->thumbnail && $align_image == "center" ): ?>
                    <div class="bt-center">
                    <a target="<?php echo $openTarget; ?>"
                        class="bt-image-link<?php echo $modal? ' modal':''?>"
                        title="<?php echo $row->title;?>" href="<?php echo $modal?$row->mainImage:$row->link;?>">
                        <img <?php echo $imgClass ?> src="<?php echo $row->thumbnail; ?>" alt="<?php echo $row->title?>"  style="width:<?php echo $thumbWidth ;?>px;" title="<?php echo $row->title?>" />
                    </a>
                    </div>
                    <?php endif ; ?>


                    <?php if( $show_intro ): ?>
                    <div class="bt-introtext">
                    <?php echo $row->description; ?>
                    </div>
                    <?php endif; ?>

                    <?php if( $showReadmore ) : ?>
                    <p class="readmore">
                        <a target="<?php echo $openTarget; ?>"
                            title="<?php echo $row->title;?>"
                            href="<?php echo $row->link;?>"> <?php echo JText::_('READ_MORE');?>
                        </a>
                    </p>
                    <?php endif; ?>

                </li>
                <!--end bt-inner -->
            </ul>
            <!--end bt-row -->
            <!--CONTENT-->
            <?php endforeach; ?>
            <div style="clear: both;"></div>
        </div>
        <!--end bt-main-item page   -->
        <?php endforeach; ?>
    </div>

    <?php if( $next_back && $totalPages  > 1  ) : ?>
    <a class="prev" href="#"></a><a class="next" href="#"></a> 
    <?php endif; ?>

</div>
<!--end bt-container -->
<div style="clear: both;"></div>

<script type="text/javascript"> 
    if(typeof(btcModuleIds)=='undefined'){var btcModuleIds = new Array();var btcModuleOpts = new Array();}
    btcModuleIds.push(<?php echo $module->id; ?>);
    btcModuleOpts.push({
            slideEasing : '<?php echo $slideEasing; ?>',
            fadeEasing : '<?php echo $slideEasing; ?>',
            effect: '<?php echo $effect; ?>',
            preloadImage: '<?php echo $preloadImg; ?>',
            generatePagination: <?php echo $paging ?>,
            play: <?php echo $play; ?>,                     
            hoverPause: <?php echo $hoverPause; ?>, 
            slideSpeed : <?php echo $duration; ?>,
            autoHeight:<?php echo $autoHeight ?>,
            fadeSpeed : <?php echo $fadeSpeed ?>,
            equalHeight:<?php echo $equalHeight; ?>,
            width: <?php echo $moduleWidth=='auto'? "'auto'":$params->get( 'module_width', 0 ); ?>,
            height: <?php echo $moduleHeight=='auto'? "'auto'":$params->get( 'module_height', 0 ); ?>,
            pause: 100,
            preload: true,
            paginationClass: '<?php echo $butlet==1 ? 'bt_handles': 'bt_handles_num' ?>',
            generateNextPrev:false,
            prependPagination:true,
            touchScreen:<?php echo $touchScreen ?>
    });
</script>
<?php 
    // set position for bullet
    if($butlet) {
        $nav_top = (-1)*(int)$params->get( 'navigation_top', 0 );
        $nav_right = (-1)*(int)$params->get( 'navigation_right', 0 )+5;
        if(trim($params->get('content_title'))) $nav_top += 13;
        $document->addStyleDeclaration(
            $modid . ' ' . ($butlet == 1 ? '.bt_handles' : '.bt_handles_num') . '{'.
                'bottom: ' . '5% !important;'.
                'right: ' . '50% !important'.
            '}'
        );

    }
    // set responsive for mobile device
    if($moduleWidth=='auto'){
    $document->addStyleDeclaration(
        '
        @media screen and (max-width: 480px){.bt-cs .bt-row{width:100%!important;}}'
    );
    }
}
else
{ 
    echo '<div>No result...</div>'; 
} ?>

Any Help Greatly apreciated.

  • 写回答

2条回答 默认 最新

  • dongya1875 2013-03-19 07:55
    关注

    you can do something like this. basicly, set a boolean to only do something different to the first item:

    <?php $first = true; ?>
    <?php foreach( $pages as $key => $list ): ?>
    <?php 
        if($first) {
            /* put this $list in its own div or whatever you need to do */
            $first = false;
        } else {
            ... //the default operation/code
    ?>
    ...
    <?php } ?>
    <?php endforeach; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器