' . $r['title_li'] . ''; } return $output; } /** * Create HTML list of pages, with unlinked parent pages. * Based on Walker_Page class from wp-includes/post-template.php * * @uses Walker */ class Walker_Page_Unlink_Parents extends Walker { var $tree_type = 'page'; var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID'); // Define six new member variables to hold the option settings, and the list of all page objects var $option_dummy = 1; var $option_unlink_current = 0; var $option_remove_titles = 0; var $option_maxdepth = 9999; var $option_unlink_array = array(); var $all_pages = array(); // Define a constructor to load the option settings from the db, and initialize the page object list function Walker_Page_Unlink_Parents() { $unlink_options = get_option('ambrosite_unlink_parents'); $this->option_dummy = is_null($unlink_options['dummy']) ? 1 : $unlink_options['dummy']; $this->option_unlink_current = $unlink_options['unlink_current']; $this->option_remove_titles = $unlink_options['remove_titles']; $this->option_maxdepth = ( $unlink_options['maxdepth'] ) ? $unlink_options['maxdepth'] : 9999; if ( $unlink_options['expages'] ) $this->option_unlink_array = array_map( 'intval', explode(',', $unlink_options['expages']) ); $all_pages_wp_query = new WP_Query(); $this->all_pages = $all_pages_wp_query->query( array('post_type' => 'page', 'posts_per_page' => -1) ); } function start_lvl(&$output, $depth) { $indent = str_repeat("\t", $depth); $output .= "\n$indent\n"; } // This is the only method that has been modified from the core Walker_Page class. function start_el(&$output, $page, $depth, $args, $current_page) { if ( $depth ) $indent = str_repeat("\t", $depth); else $indent = ''; extract($args, EXTR_SKIP); $unlink_current = false; $css_class = array('page_item', 'page-item-'.$page->ID); if ( !empty($current_page) ) { $_current_page = get_page( $current_page ); if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) ) $css_class[] = 'current_page_ancestor'; if ( $page->ID == $current_page ) { $css_class[] = 'current_page_item'; if ( $this->option_unlink_current ) $unlink_current = true; } elseif ( $_current_page && $page->ID == $_current_page->post_parent ) $css_class[] = 'current_page_parent'; } elseif ( $page->ID == get_option('page_for_posts') ) { $css_class[] = 'current_page_parent'; } $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page)); // Begin modified code. Find any child pages, and if they exist, unlink the parent page (if at a depth less than maxdepth). $page_children = get_page_children($page->ID, $this->all_pages); $link_open = 'option_maxdepth || in_array($page->ID, $this->option_unlink_array) || $unlink_current ) { if ( $this->option_dummy ) { $link_open = 'option_remove_titles ) ? '' : ' title="' . esc_attr(apply_filters('the_title', $page->post_title)) . '"'; $output .= $indent . '
  • ' . $link_open . $page_title . '>' . $link_before . apply_filters('the_title', $page->post_title) . $link_after . $link_close; // End of modified code. 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 .= "
  • \n"; } } function ambrosite_unlink_parents_adminpage() { ?>

    Ambrosite Unlink Parent Pages - Options

    term_id) ) { echo '

    IMPORTANT: Unlink Parent Pages has detected custom menus. This plugin is not compatible with the WordPress 3.x custom menu system (that is, menus created using the drag-and-drop menu builder under Appearance->Menus). If you want to create an unlinked parent menu item with the menu builder, use a \'Custom Link\' with a \'#\' (hash/pound) mark in the URL field.

    '; break; } } ?>
    />

    In some themes, unlinking the parent pages may cause problems with CSS styling. If that happens, try using dummy links instead. A dummy link is just like a regular link, except that it leads back to the current page when clicked. (Turned on by default as of Unlink Parent Pages version 1.3)

    />

    Unlink the current page, in addition to the parent pages.

    />

    Remove the title attribute from the links. Stops the tooltip from popping up when the mouse hovers over the menu items.

    Controls how many levels in the page hierarchy are to be unlinked. Works exactly like the 'depth' option for wp_list_pages.

    • 0 (default) Unlinks all parent pages, anywhere in the page hierarchy.
    • 1 Unlinks top-level parent pages only.
    • 2, 3, ... Unlinks parent pages to the given depth.
    • -1 Do not unlink any pages (specify individual pages below).

    You can specify which pages you want unlinked, using a comma-separated list of page IDs (example: 3,7,31). Works exactly like the 'exclude' option for wp_list_pages. If you want only these pages to be unlinked, then set max depth to -1.

    9999 ) $input['maxdepth'] = 0; $input['expages'] = preg_replace('/[^0-9,]/', '', $input['expages']); return $input; } // Init plugin options to white list the options function ambrosite_unlink_parents_init(){ register_setting( 'ambrosite_unlink_parents_options', 'ambrosite_unlink_parents', 'ambrosite_unlink_parents_validate' ); } add_action('admin_init', 'ambrosite_unlink_parents_init' ); ?>