API15

JDocumentHTML/countMenuChildren: Difference between revisions

From Joomla! Documentation

m removing red link to edit, no existant pages
m preparing for archive only
 
Line 48: Line 48:


===Examples===
===Examples===
<CodeExamplesForm />
=== Code Examples ===
<dpl>
<dpl>
  noresultsheader=\n
  noresultsheader=\n
  category=countMenuChildren
  category=countMenuChildren
  category=JDocumentHTML
  category=JDocumentHTML
  category=CodeExample
  namespace=CodeExample
  category=MethodExample
  category=MethodExample
  include=*
  include=*

Latest revision as of 00:31, 25 March 2017

Description

Count the number of child menu items

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

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

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples

Code Examples