Add </li> if item is shallower

67 Views Asked by At

I want to close a list item and unordered list, if an item is shallower.

The following code has been written, but the list isn't being closed, even if the item is shallower:

      // The next item is shallower.
  elseif ($item->shallower)
  {
    echo '</li>';
    echo str_repeat('</ul></li>', $item->level_diff);
  }
  // The next item is on the same level.
  else
  {
    echo '</li>';
  }
1

There are 1 best solutions below

1
On

Can you please try to apply code as below and check once

elseif ($item->shallower)
  {
    echo '</li><li>';
    echo str_repeat('</ul></li>', $item->level_diff);
  }
  // The next item is on the same level.
  else
  {
    echo '</li>';
  }