XF 2.2 How can I remove new posts and whats-new for guests?

Black Tiger

Active member
How do I remove the "new posts" button and whats-new for guests? I would like them to register and login to have these options.
I know I can take them away in the Public Navigation, but I do want them present for my users.
 
Solution
If you would rather use CSS, you can add this to the extra.less template to hide it:

Less:
[data-template="forum_list"][data-logged-in="false"]
{
    .p-title-pageAction .button--icon--bolt
    {
        display: none;
    }
   
}

Black Tiger

Active member
&& $xf.visitor.user_id
What is the difference between this line with and without the ! in front of it?

We're talking about different things I see. I'm sorry, didn't see there was another new posts on that part too. That is working, but I was talking about the button.

This is the button link on the right side above the sidebar. Sorry, next time I will provide a screenshot sooner. This is in Dutch language, but it is the new posts button.
1610984190674.png
 

Brogan

XenForo moderator
Staff member
Edit the forum_overview_wrapper template.

HTML:
<xf:if is="$xf.visitor.user_id">
    <xf:button href="{{ $xf.options.forumsDefaultPage == 'new_posts' ? link('forums/new-posts') : link('whats-new/posts') }}" icon="bolt">
        {{ phrase('new_posts') }}
    </xf:button>
</xf:if>
 

nicodak

Well-known member
Ha ha ! I understand well now !!

So this button can be hidden with conditional directly in template.
template concerned : forum_overview_wrapper
so try this :
HTML:
//replace this
<xf:button href="{{ $xf.options.forumsDefaultPage == 'new_posts' ? link('forums/new-posts') : link('whats-new/posts') }}" icon="bolt">
    {{ phrase('new_posts') }}
</xf:button>

//by this
<xf:if is="$xf.visitor.user_id">
    <xf:button href="{{ $xf.options.forumsDefaultPage == 'new_posts' ? link('forums/new-posts') : link('whats-new/posts') }}" icon="bolt">
        {{ phrase('new_posts') }}
    </xf:button>
</xf:if>
 

Black Tiger

Active member
I presume that "v" is a typo Brogan.

@nicodak Thank you too.

Be aware that there since a new "if" statement is create, also a new </xf:if> is needed otherwise it will display an error.

Got it like this now and that is working:
Code:
    <xf:if is="$xf.visitor.user_id">
        <xf:button href="{{ $xf.options.forumsDefaultPage == 'new_posts' ? link('forums/new-posts') : link('whats-new/posts') }}" icon="bolt">
            {{ phrase('new_posts') }}
        </xf:button>
        </xf:if>
    </xf:if>

You got that, but you got the original in the "replace by". :)

Thank you all very much for thinking with me and again my apology's, I thought it was clear, because I wrote "button" in my initial message.
 

Black Tiger

Active member
Thank you Brogan. I rather use extra.less then editing templates. I will add it to extra.less.

What is the difference between $xf.visitor.user_id and !$xf.visitor.user_id with the ! in front of it?
 

Brogan

XenForo moderator
Staff member
The is attribute supports logical operators:
  • OR / || - used to link alternative conditions
  • AND / && - used to link additional conditions
  • ! - place before a condition to invert it
  • XOR - returns true if only one of two conditions is true

$xf.visitor.user_id applies to logged in members, !$xf.visitor.user_id applies to logged out guests.
 
Top