在WordPress MU首页调用登陆接口的方法

前面在帮别人做(应该是“改”)一个带博客系统小网站时,用的wordpress mu,然后看到一款模板挺好用的,于是想把它改成wordpress的模板,结果那个模板有个从首页登陆的登陆框,于是想物尽其用,在网上找了一些代码, 把登陆接口放在了首页,下面就把代码贴出来吧(别人的代码,加上我调用时做的部分修改):

(把这断代码添加到functions.php末尾,再调用)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function home_page_login_form() {
global $current_user, $blog_id;
if ( ! is_user_logged_in() ) {
?>
<form name="loginform" id="loginform" action="wp-login.php" method="post">
<h2>用户登陆</h2>
<label>用户名:&nbsp;</label><br />
<input type="text" name="log" id="log" class="textInput" value="" tabindex="1" /><br />
<label>密码:&nbsp;</label><br />
<input type="password" name="pwd" class="textInput" value="" tabindex="2" />
<br /><input name="rememberme" type="checkbox" id="rememberme" value="forever" style=" width: 20px; " />记住我
<input type="hidden" name="redirect_to" value="/" />
<br /><input name="submit" type="submit" class="button" value="登陆" />
<div id="register"><a href="wp-signup.php">现在注册</a></div>
</form>
<?php
} else {
$blogs = get_blogs_of_user($current_user->ID);
$username = $current_user->user_login;
$siteurl= get_settings('siteurl');
?>
<form>
<h2>Hi, <?php echo $username; ?>!</h2><br />&nbsp;
<?php printf( __( "<a href='%s&amp;redirect_to=%s'>注销</a>"), wp_nonce_url( site_url('wp-login.php?action=logout', 'login'), 'log-out' ) , $siteurl);?>
<br><br>&nbsp;
 你的博客:
<?php
if ( ! empty($blogs) ) foreach ( $blogs as $blog ) {
$blog_id = $blog->userblog_id;
$details = get_blog_details($blog_id);
$blogname = htmlspecialchars( $details->blogname );
echo "<a href='http://" . $blog->domain . $blog->path . "'>" . $blogname . "</a> | <a href='http://" . $blog->domain . $blog->path . "wp-admin/'>管理</a>";
}
?>
</form>
<?php
}
}

效果见下图:

登陆前 登陆后

原讨论帖见:http://mu.wordpress.org/forums/topic.php?id=2730

代码文本附件:登陆代码

&nbsp

本文来自Ley's Blog,转载请注明出处。

4 thoughts on “在WordPress MU首页调用登陆接口的方法

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">