WordPress.org

Ready to get started?Download WordPress

Forums

Sidebar link to static homepage - problems (34 posts)

  1. 3stripe
    Member
    Posted 9 years ago #

    First day of testing WordPress :-)

    Have setup a site at http://www.creativeyoungteam.com/ and installed the static-homepage plugin and edited home.php to give a customised homepage.

    I then modified sidebar.php to insert a direct link to the site root for the 'Home' link, and exclude the automatic link to the page it derives from, id #6 :

    <?php wp_list_pages('sort_column=menu_order&exclude=6&title_li=<h2>' . __('Navigate') . '</h2><a href="http://www.creativeyoungteam.com" title="Home">Home</a>'); ?>

    This has produced a couple of problems I can't seem to fix:

    1. The homepage link is prefixed with a backslash "\" for some reason, and thus doesn't work

    2. The homepage link sits outside of the list of the other pages, and doesn't have the '>>' prefix which the other page links do.

    If you look under 'Navigate' on the right at http://www.creativeyoungteam.com/ you should see what I mean...

    Any tips much appreciated, have trawled through codex.wordpress.org already!

    Thanks,

    James

  2. Kafkaesqui

    Posted 9 years ago #

    This should work:

    <?php wp_list_pages('sort_column=menu_order&exclude=6&title_li=<h2>' . __('Navigate') . '</h2><ul><li><a href=http://www.creativeyoungteam.com title=Home>Home</a></li></ul>'); ?>

    There may be a tiny bit of extra space between the home link and the first Page link, but you can tweak that in the css.

    Note this is invalid XHTML; I left the quotes off the anchor attributes. Parameters for wp_list_pages() are passed in query-string style format, and one limitation is you cannot provide quotes as part of a parameter's value. We need a list_pages() function (i.e. one that accepts parameters in the PHP style, and is not so limited).

  3. 3stripe
    Member
    Posted 9 years ago #

    Thanks Kafkaesqui, worked a treat!

    About the invalid XHTML, are you saying there is no way around this problem???

  4. Kafkaesqui

    Posted 9 years ago #

    "are you saying there is no way around this problem?"

    It's not that there's *no* way, but such would involve either rewriting wp_list_pages() to display a home link (so you wouldn't have to pass it through 'title_li'), or code a relacement for the tag that accepts parameters in the regular 'PHP' style.

  5. jfriesen
    Member
    Posted 9 years ago #

    interesting work around! the invalid xhtml is a downside; i'll keep looking for a standardized solution.
    JF ;)

  6. Kafkaesqui

    Posted 9 years ago #

    I've done a little digging and discovered the devs were kind enough to add an 'echo' parameter for wp_list_pages() in 1.5.1. With this we can do a little PHP magic to get valid XHTML!

    <?php
    $pages = wp_list_pages('sort_column=menu_order&exclude=6&title_li=<h2>' . __('Navigate') . '</h2><ul><li><a href="http://www.creativeyoungteam.com" title="Home">Home</a></li></ul>&echo=0');
    echo stripslashes($pages);
    ?>

    I slipped the quotes back on the anchor attributes, and added &echo=0 at the end of the parameter query to tell wp_list_pages() to return, and not echo (i.e. display) its output. That's how I'm able to assign wp_list_pages() to the $pages variable. The next line echoes the $pages variable, but first it's filtered through the stripslashes() function to remove those pesky escapes on the quotes.

    Again, this is a 1.5.1 trick only.

  7. 3stripe
    Member
    Posted 9 years ago #

    wasn't expecting a solution to this one {grin} although must admit i'm not totally sure how it works.

    thanks again... now just to remove the extra space below the homepage link that no-one else apart from us will ever notice!

    then some nice rounded corners via alistapart...

  8. 3stripe
    Member
    Posted 9 years ago #

    Somehow this has stopped working again - clicking home in the sidebar doesn't work now!!!

    Seems to have extra slashes around the link???

    <?php
    $pages = wp_list_pages('sort_column=menu_order&exclude=6&title_li=<h2>' . __('Navigate') . '</h2><ul><li><a href="http://www.creativeyoungteam.com" title="Home">Home</a></li></ul>&echo=0');
    echo stripslashes($pages);
    ?>

    Can anyone help me out at http://www.creativeyoungteam.com/ .... I also can't work out why CYT has a help cursor added to it, or why I can't add exclamation marks????

  9. Denis de Bernardy
    Member
    Posted 9 years ago #

    3stripe, I can't believe you're even asking. You're facing a documented bug, and you would know the fix if you had bothered reading the plugin's doc. As a rule, before calling for help, make sure your WP install is up to date. And that the plugin is up to date as well.

  10. 3stripe
    Member
    Posted 9 years ago #

    well, i wouldn't ask unless i didn't have a clue what i'm doing would i. have you heard of the word 'newbie'. i think that is me!!!!!

    sorry if i have offended you with my lack of knowledge, but seeing as this is a SUPPORT forum i thought maybe this would be a good place to ask the question :-P

    please forgive me!

  11. Denis de Bernardy
    Member
    Posted 9 years ago #

    nono, no problem, really, it's just... your bug is documented in the plugin's doc, which, unless I am mistaking (or then, I suggest you download the plugin again), has a link from the plugin's description! :)

  12. 3stripe
    Member
    Posted 9 years ago #

    my problem is i don't even know which plugin you are talking about yet!

    maybe you could tell me the name of the plugin and i can go do some research? is it wp_list_pages that is causing the problems or another part?

  13. 3stripe
    Member
    Posted 9 years ago #

    ok ok i got it!!! this is your plugin dennis????? that's why you think i'm an idiot!

    fair enough dude!

    think i have fixed it by starting again from scratch anyhow.

  14. Niclas
    Member
    Posted 9 years ago #

    it doesn't work at all, when I use that string of codes it makes everything in my posts and pages disapear besides the first character.

    http://niclas.pigne.net/blog

  15. Denis de Bernardy
    Member
    Posted 9 years ago #

    could you be more precise?

  16. Niclas
    Member
    Posted 9 years ago #

    http://niclas.pigne.net/enabled.jpg - this is what the layout look like when I have multiple pages and uses your hack to add a "Home" link at the top.

    http://niclas.pigne.net/disabled.jpg - without using multiple pages, this is what it should look like.

    I'm using the lates wordpress (1.5.1.2) by the way.

  17. Denis de Bernardy
    Member
    Posted 9 years ago #

    paste the code are you using

  18. Niclas
    Member
    Posted 9 years ago #


    <?php
    $pages = wp_list_pages('sort_column=menu_order&exclude=6&title_li=<h2>' . __('Navigate') . '</h2>

    <ul>
    <li><a href="./" title="Home">Home</a></li>
    </ul>
    &echo=0');
    echo stripslashes($pages);
    ?>

  19. Denis de Bernardy
    Member
    Posted 9 years ago #

    why aren't you using :

    wp_list_pages('sort_column=menu_order');

    ?

  20. Niclas
    Member
    Posted 9 years ago #

    I've changed a bit in the code now:


    <?php wp_list_pages('sort_column=menu_order&title_li=<h2>' . __('Navigation') . '</h2> <ul><li><a href="./" title="Home">Home</a></li></ul>'); ?>

    And it works as intended now, except that the home link is formatted like this:
    http://www.niclas.pigne.net/blog/%5C%22./%5C%22

    Is it the <a href="./" title="Home"> that causes all the fuss?

  21. Denis de Bernardy
    Member
    Posted 9 years ago #

    yes

  22. Niclas
    Member
    Posted 9 years ago #

  23. Denis de Bernardy
    Member
    Posted 9 years ago #

    sure it was. the quote is causing all the mess. And you should check the plugin's documentation. there is the fix.

  24. Niclas
    Member
    Posted 9 years ago #

    forgive me for asking, but what plugin? I've haven't seen any link to a plugin. All I've seen is a codesnippet that adds a home link to the navigation.

  25. moshu
    Member
    Posted 9 years ago #

    Niclas, read carefully the first two lines in the OP (original post) - it was about a plugin AND a homelink.
    So, if you are not using that plugin, start your own thread, otherwise people get confused (see above).

  26. Denis de Bernardy
    Member
    Posted 9 years ago #

  27. dmetzcher
    Member
    Posted 9 years ago #

    This is the code that I used to get a "Home" link at the top of the pages list in the sidebar.
    Edit template-functions-post.php in the wp-includes directory.
    You will only need to edit one line. Not sure if this has already been posted by someone else yet. If so, please ignore.

    Somewhere around line 324:
    (Just change the URL to your address.)

    $output .= '<li class="pagenav">' . $r['title_li'] . '<ul> <li><a href="http://www.mymacblog.com">Home</a></li>'; // Note: Forces "Home" link at top of pages list.

  28. Niclas
    Member
    Posted 9 years ago #

    thanks man! that did the trick.

  29. thatsmeinc
    Member
    Posted 8 years ago #

    dmetzcher:
    This is the best and simplest answer to create a home link in the sidebar. Thank you! I've been searching for a few hours now for a way to do this and the method outlined is the only solution which works perfectly and took, like, three second to implement. Wow.

    I read through a lot of posts by people asking for the "new to php" answer for this, so I'd like to add two helpful details. This is the exact path to the file you want to edit:
    /yourWPfolder/wp-includes/template-functions-post.php

    Then just do a search for this line:
    $output .= '<li class="pagenav">' . $r['title_li'] . '<ul>';

    and replace it with this line:
    $output .= '<li class="pagenav">' . $r['title_li'] . '<ul> <li><a href="/">Home</a></li>'; // Note: Forces "Home" link at top of pages list.

    If your wp installation is not run from your domain root, then replace the slash "/" with /yourWPdirectory

    Thanks again, dmetzcher.

  30. Apeofgod
    Member
    Posted 7 years ago #

    Hey I have a question, I'm not a php master or anything, but seem to do alright hacking together code.

    But I am a little confused, I want to use this method to put multiple links in the "menu, navigate" area but can't see to get it to work. Also, I dont want to force it to the top, though Ic an't figure out which peice of code is actually telling it to or why I can just make more then one link, I just figured copying nad pasting the link portion would do the trick, but it doesn't.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags