把html放到回声中

时间:2014-01-26 15:16:22

标签: php html wordpress echo

如何将此代码放入echo中?

<?php
if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
} else {
echo '**Here**';
}
?>

我想把代码放到回声中,我是php的新手,我试图改变“进入”或将php字符串以另一种方式放入代码中,我尝试了所有我能够在谷歌上搜索的内容我知道。但没有任何效果,我只能看到一个空白页面。 谁能帮助我了解如何更改html并使其适合回声?非常感谢你。

<div class="top-bar-login">
    <div id="adv-bar-top">Cosa aspetti ad iscriverti?</div>
    <div class="clear"></div>
<div id="other-bar-top"> 
<a href="/forums">Forum</a>  
<a href="/bacheca">Community</a>
<a href="/help">Help</a>
<a class="lbp-inline-link-2" href="#">Login</a>
<a href="/registrati" class="button-signup-top-bar">Iscriviti</a> 
    </div>
</div>
<div style="display: none;">
<div id="lbp-inline-href-2" style="padding:10px; background: #fff;">
<div id="login-form">
             <h3>Login</h3>
            <fieldset>
                <form action="<?php bloginfo('wpurl') ?>/wp-login.php" method="post">
                    <input type="text" name="log" id="log" required value="Email" onBlur="if(this.value=='')this.value='Email'" onFocus="if(this.value=='Email')this.value='' ">
                    <input type="password" name="pwd" id="pwd" required value="Password" onBlur="if(this.value=='')this.value='Password'" onFocus="if(this.value=='Password')this.value='' ">
                 <input type="submit" name="submit" value="Login">
         <input type="hidden" name="redirect_to" value="<?php echo $_SERVER['REQUEST_URI']; ?>"/>
                    <footer class="clearfix">
                        <p><span class="info">?</span><a href="/wp-login.php?action=lostpassword">Password Dimenticata?</a>
                        </p>
                    </footer>
                </form>
            </fieldset>
        </div>
        <!-- end login-form --> 
</div></div>

PS:我正在使用wordpress。

2 个答案:

答案 0 :(得分:1)

<?php
   if ( is_user_logged_in() ) {
     echo 'Welcome, registered user!';
   } else {
?>
    insert  html here
<?php
   }
?>

PHP允许这样写:

  <?php if (condition1){ ?>
      HTML or whatever if condition1 is true
  <?php }elseif (condition2){ ?>
      HTML or whatever if above is false and condition2 is true
  <?php }else{ ?>
      HTML or whatever if all above are false
  <?php } ?>

答案 1 :(得分:0)

<?php
if ( is_user_logged_in() ) {
    echo 'Welcome, registered user!';
} else {
?>Insert HTML here!<?
}
?>

它只会在is_user_logged_in() == false

中添加else的HTML