I am trying to make dynamic function where user can create list without adding <ul> <li> tag.
here is my function
function the_main_nav($navlinks){
echo '<nav>';
echo '<ul>';
$menuitem = $navlinks;
$pieces = explode(",",$menuitem);
$i=$navlinks;
while($i==','){
echo '<li>' . $pieces[$i] . '</li>';
$i++;
}
echo '</ul>';
echo '</nav>';
}
This is my template tag the_main_nav('1,2,3,44 5');
But its going into endless loop with error. I want auto generate <li> after each ',' commma. Also if possible I want anchor link within the list so it can be linked with the page.
Instead of
whileloop, useforeach: