0

这是一个很难问的问题,但是,让我们尝试一下。我正在将此模块用于 joomla 我需要为它创建一个覆盖,以便它获取第一个结果

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

并将其放在自己的 div 中并继续执行该语句。请询问是否需要任何其他信息,这是覆盖的完整代码:

<?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>'; 
} ?>

非常感谢任何帮助。

4

2 回答 2

1

你可以做这样的事情。基本上,设置一个布尔值只做与第一项不同的事情:

<?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; ?>
于 2013-03-19T07:55:52.753 回答
0

完整编辑:

使用计数器知道它是哪个迭代:

<?php $c = 0; // initialize counter
foreach( $pages as $key => $list ): 
if ($c++ == 0):
?>
this section will only run for the first element.

<?php endif;?>
于 2013-03-19T07:49:56.057 回答