【问题标题】:PHP Dynamic Count & Limit Menu itemsPHP 动态计数和限制菜单项
【发布时间】:2010-04-17 13:45:55
【问题描述】:

我想修改这段代码,它工作得很好,但是(或者我不知道,因为我是 php 新手)我无法限制菜单中主要元素显示的 li 数量。实际代码会回显它找到的所有元素,我想限制时间

<li><a href='{$sLink}' {$sOnclick} target='_parent'>{$sPictureRep}{$sText}</a>

此行已回显.. 假设仅回显前 15 个元素 + 一个“更多”按钮,在该按钮下将其余元素显示为子菜单..(这是一个 2 级水平菜单)。有人可以帮帮我吗?我真的尝试了很多,但我不是 PHP 专家..

谢谢!

   <?php 

require_once( '../../../inc/header.inc.php' );
require_once( DIRECTORY_PATH_INC . 'membership_levels.inc.php' );
require_once( DIRECTORY_PATH_ROOT . "templates/tmpl_{$tmpl}/scripts/TemplMenu.php" );

            class SimpleMenu extends TemplMenu
            {
            function getCode()
            {
            $this->iElementsCntInLine = 100;
            $this->getMenuInfo();
            $this->genTopItems();
            return $this->sCode;
            }

            function genTopItem($sText, $sLink, $sTarget, $sOnclick, $bActive, $iItemID, $isBold = false, $sPicture = '')
            {
            $sActiveStyle = ($bActive) ? ' id="tm_active"' : '';

            if (!$bActive) {
            $sAlt= $sOnclick ? ( ' alt="' . $sOnclick . '"' ) : '';
            $sTarget  = $sTarget  ? ( ' target="_parent"' ) : '';
            }

            $sLink = (strpos($sLink, 'http://') === false && !strlen($sOnclick)) ? $this->sSiteUrl . $sLink : $sLink;

            $sSubMenu = $this->getAllSubMenus($iItemID);

            $sImgTabStyle = $sPictureRep = '';
            if ($isBold && $sPicture != '') {
            $sPicturePath = getTemplateIcon($sPicture);
            $sPictureRep = "<img src='{$sPicturePath}' style='vertical-align:middle;width:16px;height:16px;' />";
            $sText = '&nbsp;';
            $sImgTabStyle = 'style="width:38px;"';
            }

            $sMainSubs = ($sSubMenu=='') ? '' : " {$sSubMenu} </a>";
            $this->sCode .= "

               <li><a href='{$sLink}' {$sOnclick} target='_parent'>{$sPictureRep}{$sText}</a>
                <div id='submenu'>
                <ul>
                 <li>{$sMainSubs}</li>
                </ul>
                </div>
               </li>
            ";
            }
            }

            $objMenu = new SimpleMenu();
            echo "<ul id='ddmenu'>";
            echo $objMenu->getCode();
            echo "</ul>";

    ?>

【问题讨论】:

    标签: php button menu count


    【解决方案1】:

    很难在代码中准确说出您想在哪里执行此操作,但我认为您正在寻找类似的内容:

    <?php
    for ($i = 0; i < 15; i ++){
        echo "<li><a href='{$sLink}' {$sOnclick} target='_parent'>{$sPictureRep}{$sText}</a>"
    }
    echo "<li><a href='more' target='_parent'>More...</a>"
    ?>
    

    【讨论】:

      猜你喜欢
      • 2014-12-04
      • 2017-05-05
      • 2013-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多