WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to create a custom menu in the style below, can this be done? The code in brackets needs to grab the actual page content for each page.

<div class="menu-button-(page-name)">
<a href="(page-link)">(page-name)</a>

How can I use that one small bit of code to create my menu? That code should generate buttons for 5 pages that are in the main tree in the admin.

share|improve this question
Is it possible to do a foreach of the main tree? – Rob Aug 30 '11 at 12:07

Rob, take a look at using register_nav_menu function in WordPress it allows you to build custom menus with ease.


share|improve this answer
up vote 0 down vote accepted
$pages = get_children(array('orderby' => 'menu_order', 'order' => 'asc'));
foreach($pages as $post) {
$fields = get_fields();

    <div class="menu-button-<?php echo $post->post_title; ?>">
        <a href="<?php echo get_page_link( $post->ID ); ?>"><?php echo $post->post_title; ?></a>
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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