WordPress.org

Ready to get started?Download WordPress

Forums

Getting the link to the first menu item (11 posts)

  1. mfuchs
    Member
    Posted 3 years ago #

    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

  2. Emil Uzelac
    Theme Review Admin
    Posted 3 years ago #

    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

  3. mfuchs
    Member
    Posted 3 years ago #

    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

  4. mfuchs
    Member
    Posted 3 years ago #

    Does anybody maybe know how to do this?

    Thanks a lot,

    Martin

  5. supertomate
    Member
    Posted 2 years ago #

    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;
    ?>
  6. roothost
    Member
    Posted 2 years ago #

    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?

  7. supertomate
    Member
    Posted 2 years ago #

    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.

  8. roothost
    Member
    Posted 2 years ago #

    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.

  9. supertomate
    Member
    Posted 2 years ago #

    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 ?

  10. roothost
    Member
    Posted 2 years ago #

    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?

  11. supertomate
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags