0

我有以下代码行:

<div align="center" style="margin-bottom: 5px; margin-top: 35px;">
<!-- AD CODE HERE -->
</div>

请关注我的网站:http ://www.electronicsforum.in/

当它是访客用户时,它会显示一条弹出消息“请登录/注册”。我对此没有任何意见。但是登录后
我想隐藏margin-top.div

4

4 回答 4

1

下面的代码解决了 www.electronicsforum.in 上的问题

global $context;
if ($context['user']['is_logged']) {
echo'<div align="center" style="margin-bottom:5px; margin-top: 5px;"> ---Ad Code Here 1-- </div>';
}
else
{
echo'<div align="center" style="margin-bottom: 5px; margin-top: 35px;"> ---Ad Code Here else-- </div>';
}
于 2014-04-11T06:43:40.910 回答
1

这不是 wordpress,它是一个名为 Simple machines Forum (SMF) 的论坛软件 .. 下面的代码只是用于 SMF 中登录用户的条件示例。

// If the user is logged in, display stuff like their name, new messages, etc.
   if ($context['user']['is_logged'])
   {
      if (!empty($context['user']['avatar']))
         echo '
            <p class="avatar">', $context['user']['avatar']['image'], '</p>';
      echo '
            <ul class="reset">
               <li class="greeting">', $txt['hello_member_ndt'], ' <span>', $context['user']['name'], '</span></li>
               <li><a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a></li>
               <li><a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a></li>';

      // Is the forum in maintenance mode?
      if ($context['in_maintenance'] && $context['user']['is_admin'])
         echo '
               <li class="notice">', $txt['maintain_mode_on'], '</li>';

此外,对于客人,相同的代码将以

 if ($context['user']['is_guest'])
       {
         echo '

这可能会帮助你们找到解决方案。

于 2014-04-10T07:53:07.607 回答
1

这是怎么回事

当前,您使用的 HTML 模板将div包含广告放在div包含告诉人们注册/登录的消息之前。由于注册/登录div需要在最上面,所以你在absolute说谎position。这迫使您margin-top在广告上使用 a div

你有两个选择。您可以使用任何构建的后端语言来检查用户是否登录,并添加一个名为的类,该类loggedindiv设置margin-top0.

第二个选项是只翻转 HTML 的输出,然后position:absolute从 register/login中删除div。由于您没有说明后端是如何构建的,因此我将向您展示如何执行第二个选项。

代码

当前的 HTML

<div align="center" style="margin-bottom: 5px; margin-top: 35px;"></div>

<div id="topbar" onclick="document.getElementById('topbar').style.visibility='hidden'; window.location=smf_scripturl + '?action=register';"></div>

<div id="wrapper" style="width: 90%"></div>

当前的 CSS:

#topbar {
    background: #ffffe0;
    border-bottom: solid 1px #F0C36D;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    display: block;
    clear: both;
    float: left;
    left: 0px;
    padding: .45em .3em .45em 2em;
    position: absolute;
    top: 0px;
    width: 100%;
}

新的 HTML(我们翻转顶部的两个divs 并删除margin-top:35px;

<div id="topbar" onclick="document.getElementById('topbar').style.visibility='hidden'; window.location=smf_scripturl + '?action=register';"></div>

<div align="center" style="margin-bottom: 5px;"></div>

<div id="wrapper" style="width: 90%"></div>

新 CSS(删除position:absolute;

#topbar {
    background: #ffffe0;
    border-bottom: solid 1px #F0C36D;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    display: block;
    clear: both;
    padding: .45em .3em .45em 2em;
    width: 100%;
}

编辑

要回复评论:您需要有条件的检查。例如,在 WordPress 中,我会写:

<div align="center" style="margin-bottom: 5px; <?php if (is_user_logged_in()) {echo 'margin-top:35px;'} ?>"></div>
于 2014-04-09T16:38:04.600 回答
0

Add in your Header:

    <?php if ( is_user_logged_in() ) { ?>
    <style type="text/css">
        #topbar{
            display:none;
        }
        body div:first-child {
            margin-top:0!important;
        }
    </style>
   <?php }?>

enter image description here

于 2014-04-10T08:02:51.577 回答