• I’ve searched Google and posts on here but I can’t find out how to make it so wp_list_pages displays results separated by commas instead of as a list ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • Add this code to functions.php:

    class Walker_Page_Comma_Separated_List extends Walker {
    	var $tree_type = 'page';
    	var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
    	var $separator = ', ';
    	var $el_count = 1;
    	function start_lvl(&$output, $depth) {
    		$output .= "<p>\n";
    	}
    	function end_lvl(&$output, $depth) {
    		$output .= "</p>\n";
    	}
    	function start_el( &$output, $page, $depth, $args, $current_page ) {
    		$output.= ( $this->el_count > 1 ) ? $this->separator : '';
    		$this->el_count++;
    		extract($args, EXTR_SKIP);
    		$href = get_page_link( $page->ID );
    		$title = apply_filters( 'the_title', $page->post_title );
    		$output .= '<a href="' . $href . '" title="' . esc_attr( $title ) . '">' . $link_before . $title . $link_after . '</a>';
    	}
    	function end_el( &$output, $page, $depth ) {
    		$output .= '';
    	}
    }

    and this code where you would like the list to be displayed in you theme:

    $walker = new Walker_Page_Comma_Separated_List();
    	wp_list_pages( array( 'title_li' => '', 'walker' => $walker ) );

    Best Wishes,
    -Mike

    Not the OP, but just wanted to thank you for posting the code that you did –?helped me understand what Walkers are and how to use/customise them. Cheers!

    Awesome, Glad to hear it!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How can I get wp_list_pages separated by commas’ is closed to new replies.