WordPress.org

Ready to get started?Download WordPress

Forums

Add Static links To Pages Menu (27 posts)

  1. ghecko
    Member
    Posted 9 years ago #

    We all know that the pages menu is created dynamically - however I would like to add a 'Home' link to the top of the menu that is created - does anyone know how I could do this.

    Thankyou

  2. Minna
    Member
    Posted 9 years ago #

    I know I've answered this a couple of times but I couldn't find the threads by quick search. So, here you go:
    <ul>
    <li><a href="<?php bloginfo('url'); ?>">Home</a></li>
    <?php wp_list_pages('title_li='); ?>
    </ul>

    The important part is that title_li parameter with empty string as its value (it won't generate ul tags), also that is why you need to add the tags manually. If you already have parameters in your wp_list_pages call just add/edit title_li accordingly.

  3. ghecko
    Member
    Posted 9 years ago #

    Hi thanks for the reply

    But when I add it like that I get the menu like this

    Home
    Pages
    About
    Contact Us

    As you can see the pages should be above the home as 'Pages' is the section title.

  4. kmtcn
    Member
    Posted 9 years ago #

    If you mean similar to the layout here:

    http://dvd.kentidwell.com

    ...Notice the (pages) menu on the right:
    FAQs (5 Main ~ 37 total)
    ==================
    HOME
    I: Installation
    II: Quality and Performance:
    III: Usage
    IV: Errors
    V: Links and more!

    ...is this what you have in mind?

    My 'Home' page (controlled via the 'Page to Front' plugin), is just like any other page of the main topic pages group, meaning it has no parent. [Main Page - (no parent)]

    I use the 'wp_list_pages' function to build the menu, and excludes to hide any I don't want, depending on which topic is currently being used.

    The way the names for the topic pages are crafted forces 'Home' to the top...move thru the various topics and notice how they expand on entry, etc.

    I can also make a link anywhere on the site, that calls that page (or also simply to the site url, of course). I try to utilize page_id's as much as possible.

    Any questions, let me know.

    Ken

  5. ghecko
    Member
    Posted 9 years ago #

    here's the code too

    <ul>
    <li><a href="<?php bloginfo('url'); ?>">Home</a></li>

    <?php wp_list_pages('title_li=<h2>' . __('Pages') . '</h2>' ); ?>
    <li>
    <h2><?php _e('Archives'); ?></h2>
    <ul>
    <?php wp_get_archives('type=monthly'); ?>
    </ul>
    </li>

  6. ghecko
    Member
    Posted 9 years ago #

    I want everything as standard apart from to add a link to the homepage at the top of the dynamic pages menu that gets created.

    My issue is as the menu is dynamically created where abouts can I place the code to make this work .

  7. kmtcn
    Member
    Posted 9 years ago #

    ghecko:

    >My issue is as the menu is dynamically created where abouts can I place the code to make this work .

    Depends on your layout, actually. Which theme? If it is same as mine (default wp 1.5), do you want it in the same location as mine?

    If so, you want to add the code to the file 'sidebar.php' - ...something like this:

    <?php wp_list_pages('title_li=<h2>' . __('Pages') . '</h2>' ); ?>

    This will list all pages, with links.

  8. ghecko
    Member
    Posted 9 years ago #

    Yeah I have the code to list the pages - my issue is I want a link back to the main homepage like http://www.mysite.com so i have to place this static link somewhere in the wp_list_pages but dont know how to.

    If i place the static link above the wp_list_pages it comes out above the section heading and below it comes out at the bottom. I guess I need a way to edit the wp_list_pages and place the static link in there.

  9. Minna
    Member
    Posted 9 years ago #

    Why don't you put the section heading (<h2>Pages</h2> or something) outside the function call and put the rest as in my code example up there?

  10. kmtcn
    Member
    Posted 9 years ago #

    ghecko:

    >so i have to place this static link somewhere in the wp_list_pages but dont know how to.

    Static link?

    I use a page, and live linking, and it goes right to the top of the site. I use crafted page titles to keep this one at the top at all times. There are various ways to force the sorting, and this one worked easy for me.

    Sorry, but I don't see why you need a static link...?

  11. Minna
    Member
    Posted 9 years ago #

    Including a link to the main page at the top -- or bottom, for that matter -- of the page list requires some extra coding and inserting the link itself before or after the wp_list_pages function call. Thus the name "static link" (not going to debate correct terminology here -- as long as people get understood).

    The title_li needs to have an empty value because otherwise the page links will be wrapped in <ul>tags and adding a <li> with the home link before the other pages will break validation. And because you can't have the section header as the value of title_li you need to add it manually.

  12. kmtcn
    Member
    Posted 9 years ago #

    >Including a link to the main page at the top -- or bottom, for that matter -- of the page list requires some extra coding....

    Not on mine...again, it's just another page, and the way the title is written, it's always at the top.

    <?php /* If this is home */ } elseif (is_page()) { ?>
    <?php wp_list_pages('exclude=74,22,85&title_li=<h2>' . __('FAQs (5 Main ~ 37 total)') . '</h2>' ); ?>

    ...works for me, validates and can be located anywhere on the sidebar.

    What am I doing wrong that makes it right?

  13. Minna
    Member
    Posted 9 years ago #

    Kmtcn, you said you're using "Page to Front" plugin. That's why it works. But ghecko doesn't need a plugin just to get that one little link in there.

  14. kmtcn
    Member
    Posted 9 years ago #

    >But ghecko doesn't need a plugin just to get that one little link in there.

    Seems ghecko does :)

  15. Minna
    Member
    Posted 9 years ago #

    Nooooo. I have Home link as the first thing of my page link list and I'm not using any plugins for that. I have that tiny little code snippet I pasted in my 1st reply. That's it.

    Let's wait for ghecko's reply now.

  16. ghecko
    Member
    Posted 9 years ago #

    hi guys

    I'm a little lost now :) so many potential fixes.

    I gues the easiest way we be if there was a way to create a Link as a page that way it would just show up automatically within the pages menu. i cant see any way to do this though.

    I am basically trying to create a simple navigation strucutre as a menu and all of the other links are fine because they are actual pages 'About us' - Contact us ' etc however I want purely a link (I call it static in the sense of it isn't auto generated) to my homepage like you see on lots of other sites.

    The code from the first post looks good but it places the 'Home' link above the 'Pages' section title - I need some way for it to create the Section Title - then insert the static link and then insert the rest of the auto generated menu.

    I'm trying to do as one of the later replies suggested creating my own 'pages' title and then add the menu but the css is all over the place at the mo as I use the
    <li> command and
    <ul> in the formatting.

  17. Minna
    Member
    Posted 9 years ago #

    What about
    <h2>Pages</h2>
    <ul>
    <li><a href="<?php bloginfo('url'); ?>">Home</a></li>
    <?php wp_list_pages('title_li='); ?>
    </ul>

    If the CSS is the only problem now, it's easy to fix.

    Of course, you could make a link category and add all the links you want to it, but it would require adding a new link every time you add a new page.

    My solution to this on my own page is this:
    <li>This site
    <ul>
    <li><a href="<?php bloginfo('url'); ?>">Home</a></li>
    <?php wp_list_pages('sort_column=menu_order&title_li='); ?>
    </ul>
    </li>

  18. ghecko
    Member
    Posted 9 years ago #

    I have it all working now apart from the CSS

    I have the normal code and my code both showing - but as you can see the lines seperating the menu are missing from my code - thats my last issue now.

    For your info here is the standard code with the lines showing correctly
    <ul>
    <?php wp_list_pages('title_li=<h2>' . __('Pages') . '</h2>' ); ?>
    </ul>

    here is my code

    <h2>Navigation</h2>
    <li><a href="<?php bloginfo('url'); ?>">Home</a></li>
    <?php wp_list_pages('title_li'); ?>

  19. Minna
    Member
    Posted 9 years ago #

    You never gave us your url :) Anyway, the original code you pasted generates something like
    <ul>
    <li id="pagenav">
    <h2>Pages</h2>
    <ul>
    <li>Page one</li>
    <li>Page two</li>
    </ul>
    </li>
    </ul>

    With an empty title_li, wp_list_pages will only generate the li tags around each link so you have to fill in the rest:
    <ul>
    <li id="pagenav">
    <h2>Navigation</h2>
    <ul>
    <li><a href="<?php bloginfo('url'); ?>">Home</a></li>
    <?php wp_list_pages('title_li'); ?>
    </ul>
    </li>
    </ul>

    That should work CSS-wise too.

    One way is to check the source generated by the original code, paste it and only replace the page link <li>s with the wp_list_pages call. That way you can't go wrong :)

  20. joox
    Member
    Posted 9 years ago #

    minna, I tried your method, and it works, except I can't figure out how to style it right!

    Check it out here... http://www.trickmydorm.com

    The navigation list is indented too much. Anyone know how to fix this in the CSS?

  21. Minna
    Member
    Posted 9 years ago #

    Hey, I replied to your email, but I'll reply here too. It seems you've got everything fixed, or am I seeing things (or actually not seeing what I'm supposed to be seeing)?

  22. StefanoVerna
    Member
    Posted 9 years ago #

    I've created a wp hack just for this problem. It creates "special pages" to link external resources. Quite simple, too. You can find it here.
    Cheers.

  23. ragecg
    Member
    Posted 8 years ago #

    Awesome Joox!
    Can you post the final code you used to get this to work?

    I can handle the css no prob, but I'm at the point that you were where my pages menu list looks like so:
    http://www.ragecg.com/bushido

    This is because my current code looks like this:

    <li><a href="<?php bloginfo('url'); ?>">Home</a></li>
    <?php wswwpx_fold_page_list ('sort_column=menu_order&title_li=<h2>' . __('MENU') . '</h2>' ); ?>

    Thanks for any help, and thanks to all of you (esspecialy you Minna!) for helping with this issue, as I will be needing it for another WP custom site I'll be doing for a client next week:)

    NOTE: As you can see, I am using the "fold_page_list" plugin in the wp_list_pages string.
    It adds some new functions to the wp_list_pages one without hurting anything:)
    Works very well btw:)

    Thanks again!

  24. Minna
    Member
    Posted 8 years ago #

    ragecg: I assume your problem is that Home is separated from the other links, right? That's because the header "Menu" is added in the fold_page_list's parametres. You can take it out (ending up with parametres 'sort_column=menu_order&title_li=') and "hard code" it right above the Home link (as <h2>__('MENU')</h2>, or just <h2>MENU</h2> without "localization function" (__('some text')).

  25. ragecg
    Member
    Posted 8 years ago #

    Thanks Minna! I will try tonight after work!

  26. ragecg
    Member
    Posted 8 years ago #

    Rock on! It worked. I bow to you!!

    Thanks much! Now onto the css....

    Thanks again all!

  27. roresteen
    Member
    Posted 7 years ago #

    Forgive me ahead of time, WP sensei's...all I'm trying to do is add a bunch of pages to my sidebar without having them defaulting under the stooooopid "Pages" heading. I need 10 different categories, some with a children, some with not. All need to be links that bring up that page's content that can be added and modified as needed.

    I assume this cannot be done through the "write page" option in the dash board; I don't mind doing things by hand inside the sidebar php file; I just want to know if there is an easier way to automate this.

    Thank you,

    Rob

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.