Skip to content

Target the posts counter in categories using CSS and jQuery

Let's Build It
  • For those who have delved as deep into styling NodeBB as I have, this is for you 🙂

    It’s relatively easy to achieve this look when a topic is updated (note the different coloured posts card)

    84655243-fa6c-4007-9588-944e4a4800e1-image.png

    Here, we simply target the below class

    body:not(.user-guest) li.unread .stats-postcount
    

    However, it’s not so simple an affair to achieve the same look in the category view as the two DIVs are identical and have no unique classes

    c4ee50a6-5f48-4cd3-a103-3a15cb9c6461-image.png

    0fe2c02c-1b7d-451c-a3c4-bbcb7ce21115-image.png

    To work around this, we can use a very simple function that adds an ID to the “posts” DIV as shown below (this is placed in /admin/appearance/customise#custom-js)

    $(document).ready(function() {
            $(window).on('action:ajaxify.end', function(data) {
        // Select the div using its class
        $('.card.card-header.border-0.p-2.overflow-hidden.rounded-1.d-flex.flex-column.align-items-center').each(function() {
            // Check if the div contains the word "Posts"
            if ($(this).text().trim().includes("Posts")) {
                // Assign the id 'catpost' to the div
                $(this).attr('id', 'updated-posts');
            }
        });
    });
    });
    

    This code will first look for the classes .card.card-header.border-0.p-2.overflow-hidden.rounded-1.d-flex.flex-column.align-items-center in the DOM, and if there, it will add the ID of updated-posts, meaning you can then target with the same CSS you are using in the recent view. See below

    c4e1119b-89dd-4cc0-b433-862d83c73782-image.png

    You’ll see that the ID has been added as required, and this means we can now adjust the original CSS so it looks like the below

    body:not(.user-guest) li.unread .stats-postcount, body:not(.user-guest) .unread #updated-posts
    

    NOTE: body:not(.user-guest) is being used so that the effect is not being applied to those who are not logged in as that wouldn’t make any sense - your mileage here may vary though.

    6d1ea244-a15d-449f-b674-db9e7063f1b4-image.png

    Doesn’t that look better? For the life of me, I can’t understand why these two elements do not have ID’s set already, but there you go.

    Enjoy.

  • Very great 😉


Related Topics
  • CSS border gradients

    Blog
    10
    2 Votes
    10 Posts
    423 Views

    ah f5 need 🙂

  • Threaded post support for NodeBB

    Let's Build It
    146
    50 Votes
    146 Posts
    20k Views

    Updated git for above change

    https://github.com/phenomlab/nodebb-harmony-threading/commit/14a4e277521d83d219065ffb14154fd5f5cfac69

  • 1 Votes
    1 Posts
    306 Views
    No one has replied
  • Create a dynamic category list

    Moved Let's Build It
    16
    14 Votes
    16 Posts
    1k Views

    Hmm - seems I never committed this code. I’ll do that now…

    EDIT - here it is

    https://github.com/phenomlab/category-list/tree/main

  • Blinking text Effect

    Customisation
    3
    5 Votes
    3 Posts
    436 Views

    @phenomlab

    I love it too

    @phenomlab said in Blinking text Effect:

    Has that “broken neon light” look that you see in films.

    It’s exactly that, kind of old neon signs of bar or pubs a bit cyberpunk too 😉

  • 11 Votes
    23 Posts
    2k Views

    @DownPW No issues. Thanks to the Google Chrome “bug”, it does have some restrictions, but works fine other than that. I have an odd issue where it doesn’t work on Firefox mobile, but works fine on Firefox desktop.

  • Avatar on Topic Header

    Solved Customisation
    9
    0 Votes
    9 Posts
    626 Views

    @jac said in Avatar on Topic Header:

    @downpw said in Avatar on Topic Header:

    Great Plugin 🙂

    I make it a bit cleaner via this CSS code:

    /*------------------------------------------------------------------*/ /*---------------- nodebb-plugin-browsing-users -----------------*/ /*------------------------------------------------------------------*/ /*Space between the avatar and the RSS icon */ .topic [component="topic/browsing-users"] { margin-bottom: -5px; padding-left: 10px; } /*Space between avatars*/ .pull-left { float: left!important; padding-right: 5px; }

    Do you have a screenshot of how this looks with the CSS change?

    Just added this change, thanks @DownPW 🙂

  • NodeBB Design help

    Solved Customisation
    8
    2 Votes
    8 Posts
    917 Views

    @riekmedia I’ve applied some new CSS to your site. Can you reload the page and try again ?

    For the record, this is what I added

    #footer { background: #2d343e; border-top: 4px solid #2d343e; font-size: 0.9em; margin-top: 70px; padding: 80px 0 0; position: relative; clear: both; bottom: 0; left: 0; right: 0; z-index: 1000; margin-left: -15px; margin-right: -338px; }

    The /categories page seems a bit messed up, so looking at that currently

    EDIT - issued some override CSS in the CATEGORIES widget

    <!--- CSS fix for overspill on /categories page - DO NOT DELETE --> <style> #footer { margin-right: -45px; } </style>

    That should resolve the /categories issue.