XF 2.2 How can I remove category from node list for a specific group?...

Luke247

Member
I want the category removed from the node list for a specific group, but I still want them to have access to that category if they have a direct link. Therefore, I don't want to remove their permissions to view the category. I just don't want it visible on the node list for that specific group.

I found a similar thread: https://xenforo.com/community/threa...ntent-visible-if-url-known-guest-only.114201/
He used the following code, but it didn't work for me:

.LoggedOut .node_7
{
display: none;
}
 
That code only applies to logged out visitors (guests).

To hide it for a specific user group you would have to use a conditional statement.
 
That code only applies to logged out visitors (guests).

To hide it for a specific user group you would have to use a conditional statement.

Actually, the code didn't work even with logged out guests. Do you think it's because I'm trying to remove a category and not just a single forum node? What code should I use to remove a category?

Thank you.
 
That's an XF1 thread.

For XF2 the code would be:
Less:
[data-logged-in="false"]
{
    .block--category1
    {
        display: none;
    }
}

Again though, it just hides it for guests, not a specific user group.
 
I want the category removed from the node list for a specific group, but I still want them to have access to that category if they have a direct link. Therefore, I don't want to remove their permissions to view the category. I just don't want it visible on the node list for that specific group.

I found a similar thread: https://xenforo.com/community/threa...ntent-visible-if-url-known-guest-only.114201/
He used the following code, but it didn't work for me:

.LoggedOut .node_7
{
display: none;
}
you want to hide the node from guests and only show it to logged in members?
You can do that with node permissions
 
That's an XF1 thread.

For XF2 the code would be:
Less:
[data-logged-in="false"]
{
    .block--category1
    {
        display: none;
    }
}

Again though, it just hides it for guests, not a specific user group.
How can I implement this code?
I want the same features to hide the forum in the interface or from the design from the visitors and make it available when entering via the link
 
That's an XF1 thread.

For XF2 the code would be:
Less:
[data-logged-in="false"]
{
    .block--category1
    {
        display: none;
    }
}

Again though, it just hides it for guests, not a specific user group.

Thank you. However, will you please tell me how I can do the opposite of this?.. I mean, how can I remove the category for everyone except a specific group (without removing permissions for everyone)?

For example, in the image below, I have the box unchecked for the category so nobody can see it on the node list. Will you please give me a code that will put the category back on the node list for a specific group only?

I imagine the code would be somewhat similar to the previous one you gave me...

dis.png
 
Last edited:
Thank you. However, will you please tell me how I can do the opposite of this?.. I mean, how can I remove the category for everyone except a specific group (without removing permissions for everyone)?

For example, in the image below, I have the box unchecked for the category so nobody can see it on the node list. Will you please give me a code that will put the category back on the node list for a specific group only?

I imagine the code would be somewhat similar to the previous one you gave me...

View attachment 268469

I may not know the best way to do this, but I did think of a way.

Create your own template, your own CSS 'less', let's say you call it CustomCSS.less
Put the CSS that shows the node in here, save it.

Like this:

Code:
    .block--category1
    {
        display: inherit !important;
    }
}
You may need to play with which display value displays it best.

While in the normal extras.less:

Code:
    .block--category1
    {
        display: none;
    }
}

Then in the PAGE_CONTAINER template, add this within the head tags:
Code:
<xf:if is="{{$xf.visitor.isMemberOf(x)}}">
<xf:css src="CustomCSS.less" />
</xf:if>

Replace X with the group ID that you want it shown to.
Use this one if you want it shown to more than 1 group:

Code:
<xf:if is="{{$xf.visitor.isMemberOf([x, y])}}">
<xf:css src="CustomCSS.less" />
</xf:if>

Replace X and Y with the group IDs you want it shown to. I haven't tested this, but in theory it should work.
 
Last edited:
I may not know the best way to do this, but I did think of a way.

Create your own template, your own CSS 'less', let's say you call it CustomCSS.less
Put the CSS that shows the node in here, save it.

Like this:

Code:
    .block--category1
    {
        display: inherit !important;
    }
}
You may need to play with which display value displays it best.

While in the normal extras.less:

Code:
    .block--category1
    {
        display: none;
    }
}

Then in the PAGE_CONTAINER template, add this within the head tags:
Code:
<xf:if is="{{$xf.visitor.isMemberOf(x)}}">
<xf:css src="CustomCSS.less" />
</xf:if>

Replace X with the group ID that you want it shown to.
Use this one if you want it shown to more than 1 group:

Code:
<xf:if is="{{$xf.visitor.isMemberOf([x, y])}}">
<xf:css src="CustomCSS.less" />
</xf:if>

Replace X and Y with the group IDs you want it shown to. I haven't tested this, but in theory it should work.

hmmm.. That didn't work.

Firstly, the code you gave me to remove the category in extra.less didn't work. However, I was able to remove the category from extra.less using this code:

CSS:
[data-template="forum_list"]
{
    .block--category
    {
        &15,
        {
            display: none;
        }
    }
}

Unfortunately, the other steps you gave me didn't work to put the category back on the node list for the specific group...
 
@Luke247
Oh sorry, I thought I was just going by Brogan's example, you'd have to adjust the code accordingly.
So now that you have THAT code in the normal CSS, if you put this into its own separate CSS like the custom one I mentioned:

Code:
[data-template="forum_list"]
{
.block--category
{
&15,
{
display: initial !important;
}
}
}
But the display, you might have to play with, you could try the 'initial' to start, 'inherit', 'inline', etc. I usually 'inspect' the element on the browser and adjust it there, to see which one display properly, then change to it in the CSS code.

But all this would still require you to put in the PAGE_CONTAINER part.
 
Hey @Luke247
I just tested it on my test board on a plain default style, it worked!

Logged out, the entire category and forums vanished. I set it to the Admin group, and it appears perfectly for my account.

Both inline and initial for Display works the same.
 
@Luke247
Oh sorry, I thought I was just going by Brogan's example, you'd have to adjust the code accordingly.
So now that you have THAT code in the normal CSS, if you put this into its own separate CSS like the custom one I mentioned:

Code:
[data-template="forum_list"]
{
.block--category
{
&15,
{
display: initial !important;
}
}
}
But the display, you might have to play with, you could try the 'initial' to start, 'inherit', 'inline', etc. I usually 'inspect' the element on the browser and adjust it there, to see which one display properly, then change to it in the CSS code.

But all this would still require you to put in the PAGE_CONTAINER part.

It worked! Brilliant! Thank you! Now please tell me, what are your thoughts about this:

Let's say I want to do the same thing for 50 categories. Each category to be displayed in the node list only for the specific user group associated to that category (like we just did... so there would be 50 different user groups (one for each category)).

Would I need to create 50 separate css templates. Then add the code (in Page_Container) 50 times?

Or is there a way to do this with only one css template and/or only one code in Page_Container...

... or is there some other way altogether?
 
Ouch, 50, then you might as well not use this .LESS process. I'd just write an entire conditional thing, example:

Code:
<xf:if is="{{$xf.visitor.isMemberOf([3])}}">
    <style>[data-template="forum_list"] { .block--category { &15, { display: initial !important; }</style>
<xf:elseif is="{{$xf.visitor.isMemberOf([4])}}" />
    <style>[data-template="forum_list"] { .block--category { &16, { display: initial !important; }</style>
<xf:elseif is="{{$xf.visitor.isMemberOf([5])}}" />
    <style>[data-template="forum_list"] { .block--category { &17, { display: initial !important; }</style>
</xf:if>
And repeat, that goes into your PAGE_CONTAINER.
Just to note, I don't know if the '[data-template="forum_list"]' will work here in the style brackets. I've never tried it before. You may have to experiment with and without it.

While I would update your main CSS that removes the category with:
Code:
[data-template="forum_list"]
{
    .block--category
        {
            display: none;
        }
}
This removes your Category 15 and just hides ALL categories, because it's just easier.
Then if you wanted certain ones to show to EVERYONE.
You would in fact need to do this in the main CSS:
Code:
[data-template="forum_list"]
{
.block--category
{
&XX,
{
display: initial !important;
}
}
}

While replacing XX with the category ID that you want to show to everyone. This might not be the cleanest way of doing it, but it seems easier to me.
 
Last edited:
Top Bottom