你好堆栈溢出的用户,我有一点问题,
我想在我的网站的上端获取头像,如果用户已登录我想要显示
头像和名称以及个人资料链接,
如果用户未登录我想显示登录和注册按钮
我只知道一点点php,我将不得不使用if else语句但是如何调用wordpress登录用户函数,
感谢
(如果您向我提供了一些有用的示例代码)
我试过这样的事情
<ul class="nav-userbox nav pull-right">
<?php
if ( is_user_logged_in() ) {
echo 'Welcome, registered user!';
<li id="menuLogin" class="dropdown">
<a class="user-buttons" title="Register" href="./register?to=">
Register
</a>
<a id="navLogin" class="dropdown-toggle user-buttons" data-toggle="dropdown" href="#">
Login
</a>
<div class="dropdown-menu login-form">
<form id="loginform" method="post" action="./login?to=">
<input id="user_login" type="text" placeholder="Email or Username" name="log"></input>
<input id="user_pass" type="password" placeholder="Password" name="pwd"></input>
<label class="checkbox inline">
<input id="rememberme" type="checkbox" value="forever" name="rememberme"></input>
Remember
</label>
<input id="wp-submit" type="submit" value="Log In" name="wp-submit"></input>
<input type="hidden" value="http://www.entrytestclass.com/main21/wp-admin/" name="redirect_to"></input>
<input type="hidden" value="" name="instance"></input>
<input type="hidden" value="login" name="action"></input>
</form>
<div class="custom">
<div id="fb-root" class=" fb_reset" style="display:inline;">
<div style="position: absolute; top: -10000px; height: 0px; width: 0px;"></div>
<div style="position: absolute; top: -10000px; height: 0px; width: 0px;"></div>
</div>
<script>
window.fbAsyncInit = function() {
…
</script>
<div class="fb-login-button fb_iframe_widget" scope="email,user_about_me,user_location,user_website" size="medium" style="display:inline; vertical-align:middle;" login_text=" " fb-xfbml-state="rendered" fb-iframe-plugin-query="app_id=332446126861609&locale=en_US&login_text=%0A%20%20%20%…about_me%2Cuser_location%2Cuser_website&sdk=joey&size=medium">
<span style="vertical-align: bottom; width: 0px; height: 0px;">
<iframe class="" height="1000px" frameborder="0" width="1000px" scrolling="no" name="f27f166a4e97fde" allowtransparency="true" title="fb:login_button Facebook Social Plugin" style="border: medium none; visibility: visible; width: 0px; height: 0px;" src="http://www.facebook.com/plugins/login_button.php?app_id=3324…about_me%2Cuser_location%2Cuser_website&sdk=joey&size=medium"></iframe>
</span>
</div>
</div>
</div>
</li>
}
?>
</ul>
但是我得到了错误,请有人告诉我我做错了什么
答案 0 :(得分:0)
例如;
<?php
if ( is_user_logged_in() ) {
if (function_exists('get_avatar')) {
echo get_avatar( get_the_author_meta('user_email'), 68 );
the_author_meta('display_name');
}
} else {
echo '<a href="'.wp_login_url( get_permalink() ).'" title="Login">Login</a>
}
?>
您的代码必须是这样的,
<ul class="nav-userbox nav pull-right">
<?php
if ( is_user_logged_in() ) {
echo 'Welcome, registered user!';
}
else { ?>
<li id="menuLogin" class="dropdown">
<a class="user-buttons" title="Register" href="./register?to=">
Register
</a>
<a id="navLogin" class="dropdown-toggle user-buttons" data-toggle="dropdown" href="#">
Login
</a>
<div class="dropdown-menu login-form">
<form id="loginform" method="post" action="./login?to=">
<input id="user_login" type="text" placeholder="Email or Username" name="log"></input>
<input id="user_pass" type="password" placeholder="Password" name="pwd"></input>
<label class="checkbox inline">
<input id="rememberme" type="checkbox" value="forever" name="rememberme"></input>
Remember
</label>
<input id="wp-submit" type="submit" value="Log In" name="wp-submit"></input>
<input type="hidden" value="http://www.entrytestclass.com/main21/wp-admin/" name="redirect_to"></input>
<input type="hidden" value="" name="instance"></input>
<input type="hidden" value="login" name="action"></input>
</form>
<div class="custom">
<div id="fb-root" class=" fb_reset" style="display:inline;">
<div style="position: absolute; top: -10000px; height: 0px; width: 0px;"></div>
<div style="position: absolute; top: -10000px; height: 0px; width: 0px;"></div>
</div>
<script>
window.fbAsyncInit = function() {
…
</script>
<div class="fb-login-button fb_iframe_widget" scope="email,user_about_me,user_location,user_website" size="medium" style="display:inline; vertical-align:middle;" login_text=" " fb-xfbml-state="rendered" fb-iframe-plugin-query="app_id=332446126861609&locale=en_US&login_text=%0A%20%20%20%…about_me%2Cuser_location%2Cuser_website&sdk=joey&size=medium">
<span style="vertical-align: bottom; width: 0px; height: 0px;">
<iframe class="" height="1000px" frameborder="0" width="1000px" scrolling="no" name="f27f166a4e97fde" allowtransparency="true" title="fb:login_button Facebook Social Plugin" style="border: medium none; visibility: visible; width: 0px; height: 0px;" src="http://www.facebook.com/plugins/login_button.php?app_id=3324…about_me%2Cuser_location%2Cuser_website&sdk=joey&size=medium"></iframe>
</span>
</div>
</div>
</div>
</li>
<?php } ?>
</ul>