有没有想过不用跑到登录界面,直接在首页就能登录到 WordPress 后台呢?实际上已经有人做到了,先帖几张屏幕截图,是在本站使用的 BLIX 主题下测试,WordPress 的版本是2.2,原作者说他在 2.1 也做过测试,在以前的版本好像就不兼容了。
登录窗口:

登录之后:

详细代码如下:
<li> <?php global $user_ID, $user_identity, $user_level ?> <?php if ( $user_ID ) : ?> <h2>Control panel</h2> <ul> <li>Identified as <strong><?php echo $user_identity ?></strong>. <ul> <li><a href="<?php bloginfo('url') ?>/wp-admin/">Dashboard</a></li> <?php if ( $user_level >= 1 ) : ?> <li><a href="<?php bloginfo('url') ?>/wp-admin/post-new.php">Write an article</a></li> <?php endif // $user_level >= 1 ?> <li><a href="<?php bloginfo('url') ?>/wp-admin/profile.php">Profile and personal options</a></li> <li><a href="<?php bloginfo('url') ?>/wp-login.php?action=logout&redirect_to=<?php echo urlencode($_SERVER['REQUEST_URI']) ?>">Exit</a></li> </ul> </li> </ul> <?php elseif ( get_option('users_can_register') ) : ?> <h2>Identification</h2> <ul> <li> <form action="<?php bloginfo('url') ?>/wp-login.php" method="post"> <p> <label for="log"><input type="text" name="log" id="log" value="<?php echo wp_specialchars(stripslashes($user_login), 1) ?>" size="22" /> User</label><br /> <label for="pwd"><input type="password" name="pwd" id="pwd" size="22" /> Password</label><br /> <input type="submit" name="submit" value="Send" class="button" /> <label for="rememberme"><input name="rememberme" id="rememberme" type="checkbox" checked="checked" value="forever" /> Remember me</label><br /> </p> <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/> </form> </li> <li><a href="<?php bloginfo('url') ?>/wp-register.php">Register</a></li> <li><a href="<?php bloginfo('url') ?>/wp-login.php?action=lostpassword">Recover password</a></li> </ul> <?php endif // get_option('users_can_register') ?> </li>
如果你需要这样的 Widget,请到这里下载侧边栏的登录窗口 Widget
由 Leojn 翻译自翻译自:Most Desired WordPress Hacks: 11 Common Requests and Fixes 第三点。感谢 Leojn.

Lia | 2008-09-02 09:04:13 | #
上周我试了一下类似的代码,没有用widget,碰到的问题是:登录后页面返回仍显示未登录,但是其他页面却显示已登录,我估计是wp super cache所引起,不知有何办法解决。
支持 反对