2

I am trying to convert html to Drupal 7 theme.

function theme_menu_tree($variables){ return '<ul class="my-class-1">' . $variables['tree'] . '</ul>'; }

simply returns the entire menu how to make it like following <ul class="my-class-1"> <li class="dropdown">Item <ul class="my-class-2"> <li>Link1</li> <li>Link2</li> </ul> </li> </ul>

1 Answer 1

0

Use theme_item_list function for it, see the below code

$title = 'Title';
$type = 'ol';
$items = array(
  'one',
  'two',
  'three',
  'four',
  'five',
);
$items[] = array(
  'data' => 'something',
  'class' => array('dummy'=>'category'),
  'children' => array('1.1','1.2',array('data'=>'1.3','class' => array('dummy'=>'category'),'children'=>array('1.3.1','1.3.2')))
);
$attributes = array('class' => array('test-class', 'demo-class'));

print theme_item_list(array(
  'items' => $items,
  'title' => $title,
  'type' => $type,
  'attributes' => $attributes
));

This will give you following HTML output:

<div class="item-list"><h3>Title</h3>
  <ol class="test-class demo-class">
    <li class="first">one</li>
    <li>two</li>
    <li>three</li>
    <li>four</li>
    <li>five</li>
    <li class="category last">something
      <div class="item-list">
        <ol class="category">
          <li class="first">1.1</li>
          <li>1.2</li>
          <li class="category last">1.3
            <div class="item-list">
              <ol class="category">
                <li class="first">1.3.1</li>
                <li class="last">1.3.2</li>
              </ol>
            </div>
          </li>
        </ol>
      </div>
    </li>
  </ol>
</div>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.