Back Home

Open Designs

Community. Driven.

    • CommentAuthorJames
    • CommentTimeNov 13th 2008
     
    Hi all,

    I want to put a simple text link at the bottom of my site to Login to Wordpress if a user is not logged in.

    If a user is logged in I want 2 links, 1 for Site Admin and the other to Logout.

    I'm not too hot on PHP or Wordpress - could anybody help me with this?

    Thanks,

    James
    • CommentAuthorainslie
    • CommentTimeNov 13th 2008
     
    I think you'll need a combination of these:

    1) http://codex.wordpress.org/Function_Reference/is_user_logged_in

    2) http://codex.wordpress.org/Template_Tags/wp_loginout

    That should get you on the right track.
    • CommentAuthorJames
    • CommentTimeNov 13th 2008
     
    Thanks for the quick reply ainslie.

    I tried using this code:

    <?php if (is_user_logged_in()){
    echo "<a href="/wp-admin/">Site Admin</a> :: <a href="/wp-login.php?action=logout">Logout</a>";
    }
    else {
    echo "<a href="/wp-login.php">Login</a>";
    };
    ?>


    which didn't work - here is the error message:

    Parse error: syntax error, unexpected '=' in D:\Domains\james-morrison.org\wwwroot\wp-content\themes\ambience\footer.php on line 64

    I'm guessing I can't use links with this code is there any easy way round this?

    Or how do I edit:

    <?php wp_loginout(); ?>

    Thanks.
    • CommentAuthorJames
    • CommentTimeNov 13th 2008
     
    Ok I figured it out with a little help from Google - just needed a "\" before the quotes for the URL.
    • CommentAuthorainslie
    • CommentTimeNov 13th 2008 edited by ainslie on the 13th November 2008 at 16:18:52 EST
     
    Glad to see you got there :-)

    All the double quotes confuse php. I used a single ' around the outside and a double " on the URL on the inside. Saves having to escape things with the \.
    • CommentAuthorJames
    • CommentTimeNov 13th 2008 edited by James on the 13th November 2008 at 17:40:55 EST
     
    Another quick question, how do I do a 301 redirect in Wordpress to ensure that the URL has a www. prefix?

    i.e. "www.james-morrison.org" instead of "james-morrison.org"

    I know this is the redirect code:

    <?
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: http:www.example.com/newpage.html" );
    ?>

    but what do I need to add so this code only runs without the www. prefix?

    I'm hosted on an IIS server so can't rely on .htaccess

    I tried searching for a plugin but couldn't find anything useful...

    Thanks
    • CommentAuthorainslie
    • CommentTimeNov 13th 2008
     
    Most people want to do the opposite and get rid of the www.

    Hence:


    <?php
    if ( !strstr( $_SERVER['HTTP_HOST'], 'www.' ) )
    return;

    header('HTTP/1.1 301 Moved Permanently');
    header('Location: http://' . substr($_SERVER['HTTP_HOST'], 4) . $_SERVER['REQUEST_URI']);
    exit();

    ?>


    I suppose you would need to test for a missing www and then prefix the www to the uri but I'm not a PHP genius so not sure how to do that.
    • CommentAuthorniemion
    • CommentTimeNov 13th 2008
     
    Posted By: ainslieMost people want to do the opposite and get rid of the www.

    It's still being discussed though.

    With Or Without .www
    To Www Or Not To Www
    With "www" or without "www" better?

    I myself prefer without "www". However, I prefer to include "www" if it's going to get printed. (Business cards, etc.)
    • CommentAuthorainslie
    • CommentTimeNov 14th 2008
     
    My web experience has grown up around WordPress so there is a tenancy to go without the www although either will get you to my website. I try to be consistent and drop the www.

    I can't remember what it is called but there is a .htaccess type thing for IIS where you can do rewrite and redirects. Had a client who bought Windows hosting with IIS for a WordPress install and all that goes with it. Never did get some things running properly. Much easier on Apache!

    Sorry I'm not much help.
    • CommentAuthorJames
    • CommentTimeNov 14th 2008
     
    I have set up the site and Google's webmaster tools for www. so I think I should stick to it.

    Wordpress on IIS can be a challenge particularly with setting permalinks so you don't have to include index.php - I discovered a simple solution using 404 redirects and wrote an article about it.

    @ ainslie: I tried to adapt the code you use for redirecting to www. - I ended up stuck in a redirect loop but found out that the homepage redirects anyway (sub pages don't) so I'm not too worried.
    • CommentAuthorainslie
    • CommentTimeNov 16th 2008
     
    I think that it will be a feature in the final WordPress 2.7.

    In their words: "Canonical redirects only do yes-www or no-www redirection for domains."

    More here: http://wordpress.org/development/2008/11/wordpress-27-beta-3/