Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm having trouble displaying two custom drop-down menus in the WP admin bar. What I want is the first drop-down to display the back-end (editing part) links of every page and the other to display the front-end links of every page. Right now, only the last foreach statement being called displays. Any suggestions are much appreciated.

function admin_bar_link() {

global $wp_admin_bar;
if ( !is_super_admin() || !is_admin_bar_showing() )
return;

$pages = get_pages();
$nurs = get_site_url();

$wp_admin_bar->add_menu( array(
    'id' => 'this',
    'title' => __($nurs),
    'href' => $nurs
) );
$wp_admin_bar->add_menu(array (
    'id' => 'edit_pages_links',
    'title' => __('Edit Pages'),
'href' => false
) );
$wp_admin_bar->add_menu(array (
    'id' => 'view_pages_links',
    'title' => __('View Pages'),
    'href' => false
) );

// added edit pages link 12-20-13 mlm
foreach ( $pages as $page ) {
    $title = $page->post_title;
    $url = get_permalink ( $page->ID )  . 'wp-admin/post.php?post=' . $page->ID . '&action=edit'; //edit post url   

     $wp_admin_bar->add_menu ( array ( //display top-level menu item 'edit pages'
        'title' => $title,
        'href' => $url,
        'parent' => 'edit_pages_links'
        )
    );

}//end foreach  

foreach ( $pages as $page ) {
$title = $page->post_title;
$url = get_permalink ( $page->ID ) . '?p='. $page->ID;

    $wp_admin_bar->add_menu ( array ( //display top-level menu item 'edit pages'
        'title' => $title,
        'href' => $url,
        'parent' => 'view_pages_links'
        )
    );                          
 }//end foreach 

}
add_action('admin_bar_menu', 'admin_bar_link');
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.