WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Class Reference/Walker Page

Contents

Introduction

The Walker_Page class was implemented in WordPress 2.1 to help create HTML list of pages. It extends the Walker class. You can also extend this class to add your own logic.

Usage

 <?php 
$walker_page 
= new Walker_Page();
$walker_page->walk($pages_array$max_depth); 

Examples

This example shows how to print a list of pages and display all levels:

<?php
$walker_page = new Walker_Page();
echo '<ul>'.$walker_page->walk(get_pages(), 0).'</ul>'; // 0 means display all levels.

The first parameter of method walk accepts an array of pages, in this case, we get the array of pages using the method get_pages.

The second parameter is the max depth option.

  • Passing -1 to max depth means flatly display every element.
  • 0 means display all levels.
  • Any number greater than 0 specifies the number of display levels.

Print list of all root pages:

<?php
$walker_page = new Walker_Page();
echo '<ul>'.$walker_page->walk(get_pages(), 1).'</ul>';

Print list of all root pages including child pages:

<?php
$walker_page = new Walker_Page();
echo '<ul>'.$walker_page->walk(get_pages(), 2).'</ul>';

Print list of all level but display it flatly. No inner <ul> element:

<?php
$walker_page = new Walker_Page();
echo '<ul>'.$walker_page->walk(get_pages(), -1).'</ul>';

Change Log

Source File

Walker_Page is located in wp-includes/post-template.php

Related