Insert a new $counter
variable before the foreach loop starts, and at the very end of the loop, call $counter++
to increment the number. In the middle, just echo out the $counter
variable.
<?php
$pages = get_children(array('orderby' => 'menu_order', 'order' => 'asc'));
// Add a counter before foreach starts
$counter = 1;
foreach($pages as $post) {
setup_postdata($post);
$fields = get_fields();
?>
<div class="menu-button-<?php echo $counter; /* echo out counter */ ?>">
<a href="https://wordpress.stackexchange.com/questions/27271/<?php echo get_page_link( $post->ID ); ?>"><?php echo $post->post_title; ?></a>
</div>
<?php
$counter++; // increment before foreach ends
}
wp_reset_query();
?>
Related Posts:
- Default menu editor with automatic page list
- Why is only the first operation run in my loop – except for on the last repeat? [closed]
- Get parents child pages
- Sticky Header in WordPress using BootstrapWP theme [closed]
- Remove nav menu item by script
- Split into two seperate unordered lists with custom walker
- How to change menu order item
- Allowing HTML in Menu Descriptions
- How to add class to parent a tag with a sub menu
- Adding an admin menu page showing the link twice – how to solve this?
- creating a custom walker class
- Creating a Mega Menu
- Walker Class – Check if menu item has description and if so add class to li
- register_nav_menus() won’t register menus
- Multiple languages menus problem
- WordPress menu performance is slow when lot of items [closed]
- How to modify wp-includes without messing my wordpress installation?
- Drag and drop isn’t working while creating menu
- How to customize submenus isn wordpress theme [closed]
- CSS Classes (optional) on menu is not showing
- HTML list menu to WordPress menu
- How can I add text to a single nav menu item?
- Displaying different page links on different pages
- Alternative to wp_get_nav_menu_items?
- One item not showing when programmatically Generating Navigation Menu
- Container class not appearing on navigation menu
- custom walker nav issue involving ajax
- Filter Menu Items by Custom User Role in a page
- list category posts under its item in menu
- Changing status of Published posts which have less Content to “Draft”
- Main menu highlighting on subpage which is not in submenu but in hierarchy
- How to re-arrange the MENU of “Allure Real Estate Theme for Placester” wordpress theme?
- Change the menu home link to something else
- pull non-wp site into content area of wordpress -or- pull wp header into non wp site?
- cross-site custom menu
- Using Zurb’s Foundation Tabs as WordPress Nav (Active Tab)
- How to remove the HOME menu item
- Help with walker for nav
- Remove admin menu
- Adding menu items?
- Create custom page and add it in nav menu by code
- Using my WordPress menu on another platform
- Header and nav menu problem on Thesis site [closed]
- API for wp menu hacks
- Links do not open from click, only in new tab [closed]
- Make a navigation menu in the same post [duplicate]
- Adding existing links to custom navigation menus?
- Dynamic_sidebar inside wp_nav_menu
- Switch from hover to click on Twenty Twelve Menu
- Remove a menu sub-item
- Create subpages in default WordPress menu
- Custom Menus: dynamic highlighting problem with custom home link
- Custom Menu Broken WP 3.8.1 Update
- Listing Child Pages in a Certain Order?
- get_the_title() gets printed out twice
- Add Buddypress profile and messages link to WordPress menu [closed]
- Can’t add a setting to the “nav_menus” customizer panel
- How to add attribute in menu code
- Use wp_logout_url() in menu creation page
- Use another menu when logged in
- Does is_child() exist in wp 3.5.1?
- register_nav_menus, then create menus programatically
- Active Menu Highlighter with Subpages?
- Redirect to another page using contact form 7? [closed]
- How to add html attributes to the “ul” html tag with “wp_nav_menu” function?
- WordPress template – How to add class to li tag if submenu exist
- Create menu without admin panel
- wp_nav_menu $theme_location parameter ignored
- Using _s theme, menu changes do not affect header menu
- Change class-name on “current_ancestor” in wp_nav_menu
- How to style a specific nav menu item?
- a better menu, menu options assistance for WP
- How to get rid of the home link in nav menu?
- wp_list_pages sort order by custom nav menu order
- Limit User Iinterface for Admin?
- Two-tone menu items
- Creating menu and breadcrumb “sections” within WordPress 3 being used as a CMS
- How to highlight 1st level menu item based on actual page
- How to truncate menu label in wordpress?
- Admin-ajax.php 500 error when Add to menu is clicked in admin
- edit user menu item
- How to remove menu labels in word press?
- Add item to top of menu using a filter in functions.php
- How to actually make menu walker alive on admin interface?
- replace existing menu programtically
- Get menus created with menu editor?
- How can I switch pages?
- Adding PHP in the menu
- How to override menu markup?
- Two menus show up
- How to remove UL class in wp_nav_menu?
- Displaying menu based on login status
- How to remove dropdown from wp_nav_menu
- In the Admin Dashboard, can I choose which sections to display?
- Can I have a different menu for each parent page?
- Create menu locations for each category in wordpress
- How can template identify what page it’s being used on?
- Add “drop-down arrow” for menu items with sub-menus
- Move Sticky Nav Menu Below WordPress Tool bar when tool bar enabled
- Conditional menu display