1

I'm new to developing a custom template in Wordpress but I fail to see how I can style a menu item seperately.

With posts I can loop through them and place them in custom html elements. With wp_page_menu() I can only output the whole list. How can I loop through each item and place them in my custom template?

Html Template:

<ul class="nav navbar-nav navbar-right is-hidden">
  <li>
   <a class="page-link" href=""> ... </a>
  </li>
  ...
  ...
</ul>
4
  • by your comment I understand you want to show navigation in your own way,,,,,rather than using default output of wordpress is this right?
    – BlueSuiter
    Commented Mar 31, 2017 at 9:45
  • Yes, that's what I want to achieve.
    – Greg
    Commented Mar 31, 2017 at 9:48
  • can you please share the html template of yours, using for navigation...
    – BlueSuiter
    Commented Mar 31, 2017 at 9:49
  • I've edited my post.
    – Greg
    Commented Mar 31, 2017 at 9:51

2 Answers 2

2

Please find below the function for showing navigation menu. Here, $menu is equivalent to Menu name, ID, or slug

<?php 
function showMyMenu($menu)
{
    $navData = wp_get_nav_menu_items($menu); 
?>
<ul class="nav navbar-nav navbar-right is-hidden">
    <?php
    foreach($navData as $k => $v)
    {   
        echo '<li><a class="page-link" href="' . $v->url . '"> ' . $v->title . ' </a></li>';
    }
    ?>
</ul>
<?php } ?>
1
  • It's my pleasure, :)
    – BlueSuiter
    Commented Mar 31, 2017 at 10:33
1

Following the code of the wp_page_menu directs me to the function get_pages. This is probably what you are looking for.

Looking at the function calls in wp_page_menu and wp_list_pages, you'll get an idea about what arguments you should pass to the get_pages function.

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.