WordPress.org

Support

Support » How-To and Troubleshooting » Sidebar link to static homepage – problems

Sidebar link to static homepage – problems

  • 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

Viewing 15 replies - 1 through 15 (of 33 total)
  • 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).

    Thanks Kafkaesqui, worked a treat!

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

    “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.

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

    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.

    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…

    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????

    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.

    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 😛

    please forgive me!

    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! 🙂

    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?

    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.

    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

    could you be more precise?

    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.

Viewing 15 replies - 1 through 15 (of 33 total)
  • The topic ‘Sidebar link to static homepage – problems’ is closed to new replies.
Skip to toolbar