侧边栏登录窗口
2008年08月31日
有没有想过不用跑到登录界面,直接在首页就能登录到 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.
11 条评论 添加你的评论 →

1. 至清 | 2008:09:01 - 02:01:36 | #
很实用的好东西。赞!
关注贵站很久,诚恳申请友情链接。
2. 雀巢 | 2008:09:01 - 11:19:08 | #
好东西,不过改起来有点麻烦,要是直接有个插件就好了
3. nobug | 2008:09:01 - 11:37:52 | #
还是习惯了去登陆界面=。=
4. 那年那月 | 2008:09:01 - 11:54:57 | #
不错,学习了
5. wangyh | 2008:09:01 - 12:20:35 | #
收藏,谢谢分享
6. hiswing | 2008:09:01 - 12:42:05 | #
好象很早以前的blog基本上都这这样的。
7. louis | 2008:09:01 - 13:58:43 | #
有些日子没来这里了!~
在这学了很多东西!
8. bssn | 2008:09:01 - 14:47:15 | #
以前用过一个主题上就有这功能。
9. iphonegirl | 2008:09:01 - 17:52:32 | #
很不错的功能,有空搞搞
10. hauy | 2008:09:01 - 18:10:49 | #
我博客用的模板就是侧边栏登录的,还用了ajax
11. Lia | 2008:09:02 - 09:04:13 | #
上周我试了一下类似的代码,没有用widget,碰到的问题是:登录后页面返回仍显示未登录,但是其他页面却显示已登录,我估计是wp super cache所引起,不知有何办法解决。