我试图在标题中的一个按钮中显示文本,根据访问者的状态显示“登录”或“注销”。这个按钮调用了一个滑块动作,所以我只需要更改上面显示的文本。
我找到了这样的代码片段,但它们进入了索引。php,我不知道如何将它们添加到按钮中。(在my header.php中)
if ( is_user_logged_in() ) {
echo \'Welcome, registered user!\';
} else {
echo \'Welcome, visitor!\';
};
我想解决办法可能是在我的。js文件,并在其中执行操作。这是我第一次尝试,不知道这是否是实现这一目标的正确方法。
jQuery(document).ready(function(){
if ( is_user_logged_in() ) {
document.getElementById("visitorstatus").innerHTML = "LOG OUT";
} else {
document.getElementById("visitorstatus").innerHTML = "LOG IN";
};
});
然后添加
<div id="visitorstatus"> 到页眉中的按钮。php?请善待我!我是PHP/JS新手
ETA标题。php
<div class="memberpresswindow">
<button type="button" class="hide-btn">X</button>
<?php echo do_shortcode( "[mepr-login-form]" ); ?>
<?php echo do_shortcode( "[mepr-membership-registration-form id=702]" ); ?>
<br>
<hr>
<button type="button" class="hide-btn">CLOSE</button>
</div>
<button type="button" class="show-btn">LOG IN | REGISTER
</button>
</div>
最合适的回答,由SO网友:RiddleMeThis 整理而成
需要PHP IF语句,is_user_logged_in().
只要在上面加上你的按钮,你就会表现得很好。这件事。。。
<?php if (is_user_logged_in()) {
echo \'<button type="button" class="show-btn">LOG IN</button>\';
} else {
echo \'<button type="button" class="show-btn">REGISTER</button>\';
}; ?>
注意:您有一个额外的
</div> 在上面的代码中。