[Resolved] Displaying Max of only 2 Category Meta links in Posts

Home Forums Support [Resolved] Displaying Max of only 2 Category Meta links in Posts

Home Forums Support Displaying Max of only 2 Category Meta links in Posts

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #815895
    Vish

    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.

    GeneratePress 2.2.2
    GP Premium 1.7.7
    #815982
    David
    Staff
    Customer Support

    Try this as your selector:

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

    #816112
    Vish

    Works perfectly! Thanks David ๐Ÿ™‚

    #816368
    David
    Staff
    Customer Support

    Awesome – glad to be of help

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.