2010-02-24 03:06:36 -05:00
|
|
|
<?php
|
|
|
|
|
2010-02-28 15:00:49 -05:00
|
|
|
/**
|
|
|
|
* Displays a list of links and thier sub items.
|
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param string $counter
|
|
|
|
* @param string $context
|
|
|
|
*/
|
|
|
|
function wp_nav_menu_get_custom_links( $counter, $context ) {
|
|
|
|
$available_links = new WP_Query( );
|
|
|
|
|
|
|
|
$args = array( 'post_status' => 'any', 'post_type' => 'nav_menu_item', 'meta_value' => 'custom' );
|
|
|
|
$link_objects = new WP_Query( $args );
|
|
|
|
|
|
|
|
$items_counter = $counter;
|
2010-02-24 03:06:36 -05:00
|
|
|
|
2010-02-28 15:00:49 -05:00
|
|
|
if ( !$link_objects->posts ) {
|
|
|
|
_e('Not Found');
|
|
|
|
return $items_counter;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display Loop
|
|
|
|
foreach ( $link_objects->posts as $item ) {
|
|
|
|
if ( 0 == $item->parent ) {
|
|
|
|
$item = wp_setup_nav_menu_item( $item, 'item', $items_counter );
|
|
|
|
|
|
|
|
switch ( $context ) {
|
|
|
|
case 'menu':
|
|
|
|
?>
|
|
|
|
<li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>">
|
|
|
|
<?php
|
|
|
|
echo wp_get_nav_menu_item( $item, 'menu' );
|
|
|
|
$parentli = $item->ID;
|
|
|
|
$items_counter++;
|
|
|
|
$items_counter = wp_nav_menu_sub_items( $item->ID, $items_counter, $parentli, 'categories', 'menu' );
|
|
|
|
?>
|
|
|
|
</li>
|
|
|
|
<?php
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'default':
|
|
|
|
?>
|
|
|
|
<li>
|
|
|
|
<?php
|
|
|
|
echo wp_get_nav_menu_item( $item, 'default' );
|
|
|
|
$parentli = $item->ID;
|
|
|
|
$items_counter++;
|
|
|
|
$items_counter = wp_nav_menu_sub_items( $item->ID, $items_counter, $parentli, 'categories', 'default' );
|
|
|
|
?>
|
|
|
|
</li>
|
|
|
|
<?php
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $items_counter;
|
|
|
|
}
|
2010-02-24 03:06:36 -05:00
|
|
|
|
2010-02-28 15:00:49 -05:00
|
|
|
/**
|
|
|
|
* Displays a list of pages and thier sub items.
|
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param string $counter
|
|
|
|
* @param string $context
|
|
|
|
*/
|
|
|
|
function wp_nav_menu_get_pages( $counter, $context ) {
|
2010-02-24 03:06:36 -05:00
|
|
|
$pages_args = array(
|
|
|
|
'child_of' => 0,
|
|
|
|
'sort_order' => 'ASC',
|
|
|
|
'sort_column' => 'post_title',
|
|
|
|
'hierarchical' => 1,
|
|
|
|
'exclude' => '',
|
|
|
|
'include' => '',
|
|
|
|
'meta_key' => '',
|
|
|
|
'meta_value' => '',
|
|
|
|
'authors' => '',
|
|
|
|
'parent' => -1,
|
|
|
|
'exclude_tree' => '',
|
|
|
|
'number' => '',
|
|
|
|
'offset' => 0 );
|
|
|
|
|
2010-02-28 15:00:49 -05:00
|
|
|
// Get all pages
|
|
|
|
$pages_array = get_pages( $pages_args );
|
2010-02-24 03:06:36 -05:00
|
|
|
|
2010-02-24 13:52:54 -05:00
|
|
|
$items_counter = $counter;
|
|
|
|
$parentli = $items_counter;
|
2010-02-24 03:06:36 -05:00
|
|
|
|
|
|
|
if ( !$pages_array ) {
|
2010-02-24 13:52:54 -05:00
|
|
|
echo __('Not Found');
|
|
|
|
return $items_counter;
|
2010-02-24 03:06:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Display Loop
|
|
|
|
foreach ( $pages_array as $post ) {
|
|
|
|
if ( $post->post_parent == 0 ) {
|
2010-02-28 15:00:49 -05:00
|
|
|
$post = wp_setup_nav_menu_item( $post, 'page', $items_counter );
|
|
|
|
if ( $context == 'menu' ) {
|
2010-02-24 03:06:36 -05:00
|
|
|
?>
|
2010-02-24 13:52:54 -05:00
|
|
|
<li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>">
|
2010-02-24 03:06:36 -05:00
|
|
|
<?php
|
2010-02-28 15:00:49 -05:00
|
|
|
echo wp_get_nav_menu_item( $post, 'menu', $items_counter );
|
2010-02-24 03:06:36 -05:00
|
|
|
$parentli = $post->ID;
|
2010-02-24 13:52:54 -05:00
|
|
|
$items_counter++;
|
2010-02-28 15:00:49 -05:00
|
|
|
$items_counter = wp_nav_menu_sub_items( $post->ID, $items_counter, $parentli, 'pages', 'menu' );
|
2010-02-24 03:06:36 -05:00
|
|
|
?>
|
|
|
|
</li>
|
|
|
|
<?php
|
2010-02-28 15:00:49 -05:00
|
|
|
} elseif ( $context == 'default' ) {
|
2010-02-24 03:06:36 -05:00
|
|
|
// Sidebar Menu
|
|
|
|
?>
|
|
|
|
<li>
|
|
|
|
<?php
|
2010-02-28 15:00:49 -05:00
|
|
|
echo wp_get_nav_menu_item( $post, 'default' );
|
2010-02-24 03:06:36 -05:00
|
|
|
$parentli = $post->ID;
|
2010-02-24 13:52:54 -05:00
|
|
|
$items_counter++;
|
2010-02-28 15:00:49 -05:00
|
|
|
$items_counter = wp_nav_menu_sub_items( $post->ID, $items_counter, $parentli, 'pages', 'default' );
|
2010-02-24 03:06:36 -05:00
|
|
|
?>
|
|
|
|
</li>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-24 13:52:54 -05:00
|
|
|
return $items_counter;
|
2010-02-24 03:06:36 -05:00
|
|
|
}
|
|
|
|
|
2010-02-28 15:00:49 -05:00
|
|
|
/**
|
|
|
|
* Displays a list of categories and thier sub items.
|
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param string $counter
|
|
|
|
* @param string $context
|
|
|
|
*/
|
|
|
|
function wp_nav_menu_get_categories( $counter, $context ) {
|
2010-02-24 03:06:36 -05:00
|
|
|
$category_args = array(
|
|
|
|
'type' => 'post',
|
|
|
|
'child_of' => 0,
|
|
|
|
'orderby' => 'name',
|
|
|
|
'order' => 'ASC',
|
|
|
|
'hide_empty' => false,
|
|
|
|
'include_last_update_time' => false,
|
|
|
|
'hierarchical' => 1,
|
|
|
|
'exclude' => '',
|
|
|
|
'include' => '',
|
|
|
|
'number' => '',
|
|
|
|
'pad_counts' => false );
|
|
|
|
|
2010-02-24 13:52:54 -05:00
|
|
|
$items_counter = $counter;
|
2010-02-24 03:06:36 -05:00
|
|
|
|
|
|
|
// Get all categories
|
2010-02-28 15:00:49 -05:00
|
|
|
$categories_array = get_categories( $category_args );
|
2010-02-24 03:06:36 -05:00
|
|
|
|
|
|
|
if ( !$categories_array ) {
|
|
|
|
_e('Not Found');
|
2010-02-24 13:52:54 -05:00
|
|
|
return $items_counter;
|
2010-02-24 03:06:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Display Loop
|
|
|
|
foreach ( $categories_array as $cat_item ) {
|
|
|
|
if ( $cat_item->parent == 0 ) {
|
2010-02-28 15:00:49 -05:00
|
|
|
$cat_item = wp_setup_nav_menu_item( $cat_item, 'category', $items_counter );
|
2010-02-24 03:06:36 -05:00
|
|
|
// Custom Menu
|
2010-02-28 15:00:49 -05:00
|
|
|
if ( $context == 'menu' ) {
|
2010-02-24 03:06:36 -05:00
|
|
|
?>
|
2010-02-24 13:52:54 -05:00
|
|
|
<li id="menu-<?php echo $items_counter; ?>" value="<?php echo $items_counter; ?>">
|
2010-02-24 03:06:36 -05:00
|
|
|
<?php
|
2010-02-28 15:00:49 -05:00
|
|
|
echo wp_get_nav_menu_item($cat_item, 'menu');
|
2010-02-24 03:06:36 -05:00
|
|
|
$parentli = $cat_item->cat_ID;
|
2010-02-24 13:52:54 -05:00
|
|
|
$items_counter++;
|
2010-02-28 15:00:49 -05:00
|
|
|
$items_counter = wp_nav_menu_sub_items( $cat_item->cat_ID, $items_counter, $parentli, 'categories', 'menu' );
|
2010-02-24 03:06:36 -05:00
|
|
|
?>
|
|
|
|
</li>
|
|
|
|
<?php
|
2010-02-28 15:00:49 -05:00
|
|
|
} elseif ( $context == 'default' ) {
|
2010-02-24 03:06:36 -05:00
|
|
|
// Sidebar Menu
|
|
|
|
?>
|
|
|
|
<li>
|
|
|
|
<?php
|
2010-02-28 15:00:49 -05:00
|
|
|
echo wp_get_nav_menu_item( $cat_item, 'default' );
|
2010-02-24 03:06:36 -05:00
|
|
|
$parentli = $cat_item->cat_ID;
|
2010-02-24 13:52:54 -05:00
|
|
|
$items_counter++;
|
2010-02-28 15:00:49 -05:00
|
|
|
$items_counter = wp_nav_menu_sub_items( $cat_item->cat_ID, $items_counter, $parentli, 'categories', 'default' );
|
2010-02-24 03:06:36 -05:00
|
|
|
?>
|
|
|
|
</li>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-02-24 13:52:54 -05:00
|
|
|
return $items_counter;
|
2010-02-24 03:06:36 -05:00
|
|
|
}
|
|
|
|
|
2010-02-28 15:00:49 -05:00
|
|
|
/**
|
|
|
|
* Recursive function that gets sub menu items.
|
|
|
|
*
|
|
|
|
* @since 3.0.0
|
|
|
|
*
|
|
|
|
* @param string $childof
|
|
|
|
* @param string $items_counter
|
|
|
|
* @param string $parentli
|
|
|
|
* @param string $context
|
|
|
|
* @param string $output_type
|
|
|
|
*/
|
|
|
|
function wp_nav_menu_sub_items( $childof, $items_counter, $parentli, $context, $output_type ) {
|
2010-02-24 13:52:54 -05:00
|
|
|
$counter = $items_counter;
|
2010-02-24 03:06:36 -05:00
|
|
|
|
|
|
|
// Custom Menu
|
|
|
|
if ( $output_type == 'menu' ) {
|
|
|
|
$sub_args = array(
|
|
|
|
'child_of' => $childof,
|
|
|
|
'hide_empty' => false,
|
|
|
|
'parent' => $childof);
|
|
|
|
} elseif ( $output_type == 'default' ) {
|
|
|
|
// Sidebar Menu
|
|
|
|
$sub_args = array(
|
|
|
|
'child_of' => $childof,
|
|
|
|
'hide_empty' => false,
|
|
|
|
'parent' => $childof);
|
|
|
|
}
|
|
|
|
|
2010-02-28 15:00:49 -05:00
|
|
|
if ( $context == 'categories' ) {
|
2010-02-24 03:06:36 -05:00
|
|
|
// Get Sub Category Items
|
|
|
|
$item_type = 'category';
|
|
|
|
$sub_array = get_categories($sub_args);
|
2010-02-28 15:00:49 -05:00
|
|
|
} elseif ($context == 'pages') {
|
2010-02-24 03:06:36 -05:00
|
|
|
// Get Sub Page Items
|
|
|
|
$item_type = 'page';
|
|
|
|
$sub_array = get_pages($sub_args);
|
|
|
|
} else {
|
|
|
|
$item_type = 'custom';
|
|
|
|
$sub_array = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( $sub_array ) {
|
|
|
|
?>
|
2010-02-28 15:00:49 -05:00
|
|
|
<ul id="sub-menu-<?php echo $context ?>">
|
2010-02-24 03:06:36 -05:00
|
|
|
<?php
|
|
|
|
// Display Loop
|
|
|
|
foreach ( $sub_array as $sub_item ) {
|
2010-02-28 15:00:49 -05:00
|
|
|
$sub_item = wp_setup_nav_menu_item( $sub_item, $item_type, $counter );
|
2010-02-24 03:06:36 -05:00
|
|
|
if ( $output_type == 'menu' ) {
|
|
|
|
?>
|
|
|
|
<li id="menu-<?php echo $counter; ?>" value="<?php echo $counter; ?>">
|
|
|
|
<?php
|
2010-02-28 15:00:49 -05:00
|
|
|
echo wp_get_nav_menu_item( $sub_item, 'menu' );
|
2010-02-24 03:06:36 -05:00
|
|
|
$counter++;
|
2010-02-28 15:00:49 -05:00
|
|
|
$counter = wp_nav_menu_sub_items( $sub_item->ID, $counter, $sub_item->ID, $context, 'menu' );
|
2010-02-24 03:06:36 -05:00
|
|
|
?>
|
|
|
|
</li>
|
|
|
|
<?php
|
|
|
|
} elseif ( $output_type == 'default' ) {
|
|
|
|
// Sidebar Menu
|
|
|
|
?>
|
|
|
|
<li>
|
|
|
|
<?php
|
2010-02-28 15:00:49 -05:00
|
|
|
echo wp_get_nav_menu_item( $sub_item, 'default' );
|
2010-02-24 03:06:36 -05:00
|
|
|
//$counter++;
|
2010-02-28 15:00:49 -05:00
|
|
|
$counter = wp_nav_menu_sub_items( $sub_item->ID, $counter, $sub_item->ID, $context, 'default' );
|
2010-02-24 03:06:36 -05:00
|
|
|
?>
|
|
|
|
</li>
|
|
|
|
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</ul>
|
|
|
|
<?php
|
|
|
|
}
|
|
|
|
return $counter;
|
|
|
|
}
|
|
|
|
?>
|