-1

我在我的 header.php 的 wordpress 主题中使用它来显示我想向未登录的用户显示的 html 块。

<?php
if ( ! is_user_logged_in() && ! ( is_page( '/register' ) || is_page( '/login' ) ) ) {
echo '';
} else {
echo '<div class="container" style="text-align:center;">
       <div class="well" style="width:1040px;margin:0    auto;background:#fbfbfb;margin-bottom:10px;">
  <h3>Welcome, visitor!</h3>
  <p style="color:#999;">Welcome to autospot.it the automotive social network! <a href="http://autospot.it/about">Learn more...</p>
  <p><a href="http://www.autospot.it/register/" class="btn btn-primary btn-large">Register</a> - or - <a href="http://www.autospot.it/login/" class="btn btn-danger btn-large">Login</a> 
  </div>
      </div>';
} 
?>

这很好用,但我也希望它不会显示在登录页面和注册页面上。

4

1 回答 1

1

用于is_page检测您的前端登录和注册页面:

<?php
    if ( ! is_user_logged_in() && ! ( is_page( 'register' ) || is_page( 'login' ) ) ) {
        echo '<div>Some stuff here</div>'; // your code
    }
?>
于 2013-05-01T14:42:25.233 回答