Support » Fixing WordPress » Getting the link to the first menu item

  • Hello all,

    Does anybody know how I can get the link to the first menu item, no matter if it’s a page or a category? The menu order can be changed and this link should then automatically point to the first item in the menu. Any help would be highly appreciated!

    Thanks a lot,
    Martin

Viewing 10 replies - 1 through 10 (of 10 total)
  • Emil Uzelac

    (@emiluzelac)

    Theme Review Admin

    Not sure if I understand your question, is this for the main WordPress menu where you list your pages, or perhaps breadcrumb in the pages itself?

    Main menu example:

    <ul class="menu">
    
    	<li><a href="<?php echo home_url(); ?>/">Home</a></li>
    	<?php wp_list_pages('title_li=' ); ?>
    
        </ul><!-- end .menu -->

    Emil

    Thanks Emil but that’s not what I meant. With WordPress 3 I am setting up my custom menu and am using a page as the first menu item. In my example it is “Portfolio”. Say in a month, I am deciding to move a different page or category from my custom menu to the first spot.

    I would like to be able to link to the first item in my WP 3 menu from the homepage, no matter if it’s the “Portfolio” page or a different page. So I am looking for a way to output the URL to this first item in my menu.

    Thanks,
    Martin

    Does anybody maybe know how to do this?

    Thanks a lot,

    Martin

    old but we can still answer isn’t it ?

    <?php
    $top = wp_get_nav_menu_items('name of the menu in admin');
    $link = $top[0]->url;
    ?>

    Did this get answered as I would also like to know?

    @supertomate not sure I follow what you have put? Where would we place that code?

    Hi roothost,
    paste it anywhere you want in header.php for example … that code do nothing for the moment, you have to use echo $link; or print_r($top); to see what is output … see more -> http://codex.wordpress.org/Function_Reference/wp_get_nav_menu_items.

    Sorry, not following. I already have a menu created I just need to be able to point to the first item in that menu from a link from the homepage.

    I don’t understand what you mean by be able to point at … do you need to retrieve the first object href of your menu ? or do you want to have the same link in an other place in your page ?

    Thinking about it, not so sure it can be done now…..

    Well I have a link on the homepage of a site http://www.corinaandco.com/ , scroll right to the commercial projects bookspine, click.

    At present that opens up a page with a menu, now I have hardcoded the link to point to a base commercial project page but the client doesn’t want that. She would like, that when you click on the bookspine, the page opens up whatever link is the first menu item in that menu.

    So, as it stands, click on the bookspine and it would open up the first menu item being ‘Liberty of London’ (thus eliminating the need for the orange ‘commercial work’ tab).

    Now the first menu item will change when she adds new content so I can’t just simply point directly to ‘Liberty of London’.

    With me?

    You would have better done to build a menu in WordPress for your main page …

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Getting the link to the first menu item’ is closed to new replies.