• Hey, quick question here. How exactly does wp_list_pages work? I’d like to pick it apart, so it’s more like the loop, and I can manipulate it better using PHP.

    Basically, I want to be able to strip the ability to see the link’s name and URL separately, and be able to reference them via PHP, though still retain the ability to do a loop-like function that will apply it for all the pages on the site, and future ones that I add.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter overshee

    (@overshee)

    I’ve found the code I need to change to do this:

    class Walker_Page extends Walker {
    	var $tree_type = 'page';
    	var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); //TODO: decouple this
    
    	function start_lvl(&$output, $depth) {
    		$indent = str_repeat("\t", $depth);
    		$output .= "\n$indent<ul>\n";
    	}
    
    	function end_lvl(&$output, $depth) {
    		$indent = str_repeat("\t", $depth);
    		$output .= "$indent</ul>\n";
    	}
    
    	function start_el(&$output, $page, $depth, $current_page, $args) {
    		if ( $depth )
    			$indent = str_repeat("\t", $depth);
    		else
    			$indent = '';
    
    		extract($args, EXTR_SKIP);
    		$css_class = 'page_item page-item-'.$page->ID;
    		if ( !empty($current_page) ) {
    			$_current_page = get_page( $current_page );
    			if ( in_array($page->ID, (array) $_current_page->ancestors) )
    				$css_class .= ' current_page_ancestor';
    			if ( $page->ID == $current_page )
    				$css_class .= ' current_page_item';
    			elseif ( $_current_page && $page->ID == $_current_page->post_parent )
    				$css_class .= ' current_page_parent';
    		}
    
    		$output .= $indent . '<li class="' . $css_class . '"><a href="' . get_ _link($page->ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' . apply_filters('the_title', $page->post_title) . '</a>';
    
    		if ( !empty($show_date) ) {
    			if ( 'modified' == $show_date )
    				$time = $page->post_modified;
    			else
    				$time = $page->post_date;
    
    			$output .= " " . mysql2date($date_format, $time);
    		}
    	}
    
    	function end_el(&$output, $page, $depth) {
    		$output .= "</li>\n";
    	}
    
    }

    however, I’d much rather do some changes in the functions.php of my theme than change this part. So, what do I have to do to make a custom function.php that can change this part of the code?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Breaking apart WP_List_Pages’ is closed to new replies.