简体   繁体   English

用户登录和注销时隐藏和显示项目

[英]Hide and Show items when user logged in and logged out

I have the following code when the user is logged out:当用户注销时,我有以下代码:

<div class="fusion-secondary-main-menu">
       <div class="fusion-row">
            <?php avada_main_menu(); ?>
            <?php avada_mobile_menu_search(); ?>
       <ul id="odp-main-menu-right" class="odp-pl-0">
            <li class="#">
                 <a href=""><i class="far fa-bell odp-mr-1">
                 </i>0</a>
            </li>
            <li id="upload-ad" class="not-logged-in">
                <a href="<?php echo wp_login_url(trailingslashit(home_url($wp->request)));?>"
                style="color: #fff;">
                NEW ADVERT
                </a>
            </li>
       </ul>
</div>

However when the user is logged out it must hide the following and when logged in show the following on the front-end:但是,当用户注销时,它必须隐藏以下内容,登录时在前端显示以下内容:

<li class="#">
    <a href=""><i class="far fa-bell odp-mr-1">
    </i>0</a>
</li>

I've used a CSS class to add display:none on a class not-logged-in but when logged in, but it is still gone.我已经使用 CSS class 在 class 上添加display:none未登录但登录时,但它仍然消失了。

When logged in, the wp_login_url must also be replaced by a clickable ID element登录时,wp_login_url 也必须替换为可点击的 ID 元素

You can use this.你可以使用这个。

<?php if(is_user_logged_in()){ ?>
    //Your HTML here needs to be shown when the user is logged in.
<?php } ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM