API15

API15:JDocumentHTML/countMenuChildren

From Joomla! Documentation

Revision as of 22:18, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Count the number of child menu items <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>[[Description:JDocumentHTML/countMenuChildren|Edit Descripto...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Description

Count the number of child menu items

[Edit Descripton]

Template:Description:JDocumentHTML/countMenuChildren

Syntax

countMenuChildren()


Returns

integer Number of child menu items

Defined in

libraries/joomla/document/html/html.php

Importing

jimport( 'joomla.document.html.html' );

Source Body

function countMenuChildren() {
        static $children;
        if(!isset($children)) {
                $dbo =& JFactory::getDBO();
                $menu =& JSite::getMenu();
                $where = Array();
                $active = $menu->getActive();
                if($active) {
                        $where[] = 'parent = ' . $active->id;
                        $where[] = 'published = 1';
                        $dbo->setQuery('SELECT COUNT(*) FROM #__menu WHERE '. implode(' AND ', $where));
                        $children = $dbo->loadResult(); 
                } else {
                        $children = 0;
                }
        }
        return $children;
}

[Edit See Also] Template:SeeAlso:JDocumentHTML/countMenuChildren

Examples

<CodeExamplesForm />