Site logo

Archived topic

Displaying Max of only 2 Category Meta links in Posts

3 replies · Started by Vish on February 20, 2019

Viewing posts 1–4 of 4

Hello

For some posts, I have more than 2 categories (in some old posts, even 4, which I noticed recently). But I want to display only 2 in the front end.

I tried the below CSS to hide the 3rd Category Meta link and display only the first 2.

span.cat-links a:nth-child(3) {
    display: none;
}

But it is not working as intended.

The problem:

It always shows one less category meta link if the count is more than 1. For example, if the post has 4 categories, it displays only 3. If it has 3, it displays 2. If it has 2, it displays 1. Thankfully, if it has 1, it simply displays the same.

What do I want to achieve?

To display only a max of 2 category meta links in the front end.

Is it possible via CSS? If yes, any help would be appreciated. :)

Thanks

Note: Have left a link to a post on my site.

Try this as your selector:

span.cat-links a:nth-of-type(1n+3)

Works perfectly! Thanks David :)

Awesome - glad to be of help

This archived topic is closed to new replies.