Consider this a complement to toscho’s solution.
I believe that …
$this->alternate = ($this->alternate != 'background_1') ? 'background_1' : 'background_2';
$css_class[] = $this->alternate;
… will do what you want.
The difference is that toscho’s solution, using the static
keyword, will make that variable static for any instantiation of this walker– that is, all instances will share the same value. If you instantiate two walkers the second will pick up where the last left off. That may be what you want, or it may not be. Using $this
will limit it to the one instance of the walker only.
Related Posts:
- $item->url not retrieving url in custom walker?
- How to prevent custom walker from creating sub navigation for pages that are not relatives of the current page?
- How can I hide children of draft pages using wp_list_pages()?
- How to List All Pages (With their template names) Within a Website
- How can I list all pages with their templates?
- Add Parent to List of Subpages
- get all page IDs from wp_list_pages
- Add class to the items in wp_list_pages
- Display grandchildren on child and grandchild pages using wp_list_pages
- Load parent pages when there are no child pages
- create shortcode to show children if any otherwise siblings
- dynamically limit depth of wp_list_pages
- Conditional styling of wp_list_pages bullet points [closed]
- Setting multiple values to as sort_column
- wp_list_pages – Using a Walker to customize output order
- Custom category listings
- How can I include private pages in a page list?
- Do Not Display Parent Page if No Subpages
- Arrange Combined List of Pages and Categories
- Make wp_list_pages print slugs instead of titles
- List pages within a certain parent and show published month
- Change Parent Name with wp_list_pages?
- List all Posts under heading in wp_list_pages menu
- wp_list_pages() but only show children on the branch you are on
- Append a code when at the current page in wp_list_pages()
- WordPress Side Navigation with Parent Heading and Child Sub Pages
- List pages to show only Whitelisted sub pages
- Get Parent List Class for Child Pages Using Walker
- List subpage of subpage
- wp_list_page with something like showpost
- How can I list all page titles and IDs?
- Hide Parent if No Children
- Add Parent to Subpage List
- active parent page when clicked on childpage
- WP List Pages – Add Title Attributes to Anchors
- wp_list_pages Hierarchical Help
- remove auto generated pages from the menu?
- Inset image thumbnail from page into list
- Exclude current page in wp_list_pages
- Sub Navigation in Sidebar
- wp_list_pages bug in “number” parameter
- Targeting specific instane of wp_list_pages
- Renaming wp_list_pages class
- wp_list_pages issue/bug?
- WordPress get_pages sub nav show current page
- Change class name in WordPress wp_list_page nav
- Non page link in wp_list_pages
- only display Pages which have children
- add a.parent in wp_list_pages
- wp_list_pages by taxonomy?
- wp_list_pages Format only on Recently Modified Pages
- Adding custom class names to anchor in wp_list_pages
- Walker Class : extract function and wp_list_pages
- Exclude pages by custom field (with yes/no) storing wrong data?
- Any walker causes blank menu?
- Custom Nav Walker menu – Display children count
- Adding Post Counts to Menu (Nav) Programmatically?
- Show top-level parent with submenu menu walker
- Adding a class (arrows) to main menu links that have children?
- Adding html elements to wp nav menu
- Bar separated navigation by extending Walker_Nav_Menu
- wp_nav_menu custom walker – child items
- Getting post content within wp_nav_walker
- Walker nav remove submenu ul from a certain depth
- Insert HTML inside link in a walker
- Trouble creating conditional PHP for nav menu items with children for custom Walker
- How to get specified parent page title in my function
- Bootstrap Navwalker not displaying
- Highlight another nav item
- WordPress empty Nav Menu error
- wordpress wp_list_pages help
- walker – 0 level on submenu formatting
- Combine get_page_by_title to exclude pages from wp_list_pages
- CSS_Menu_Walker not showing on mobile view?
- Custom megameu walker need improvement
- Exlude pages from wp_list_pages
- How to actually make menu walker alive on admin interface?
- Get parent of current page
- Exclude pages by menu order
- How do I get_the_content in a custom walker?
- How to modify the output of wp_terms_checklist when used within the built-in category metabox on edit posts?
- Change page name in admin list
- Remove a class from a using Walker
- wp_nav_menu: Is there a way to modify the output of that got a submenu?
- Creating Custom navigation in wordpress with sub menus
- How to convert the argument of wp_list_pages to an array
- How to change the menu mark up with walker_nav_menu class?
- How can I list the current pages siblings and any ancestor page siblings?
- Dynamic menu wp_list_pages displaying only current branch including: current page, his siblings and its childs
- Custom nav walker: How to acces the $args parameter?
- Add classes + taxonomy terms to wp_list_pages() output
- Disable the link on certain pages
- Hook or callback when wp_nav_menu() has completed
- wp_list_pages two columns
- Walker_Category – not reliably saving
- Extending Walker_Nav_Menu in wp_nav_menu List of Empty Items
- List pages including both parent and child pages
- Help with output of post classes using apply_filters
- Override edit_custom_walker.php to conditionally show input depending on menu position
- current_page_item and custom post type?