Following on from Adding Unique Class Names

For the category list I would recommend using ID’s they don’t change over time and are fixed at the point of creation.

I manage several Discourse instances with 50+ categories for 2 of the instances and when it get’s to this high a number ID’s are the way to go.

Now sometimes you need visibility to those ID’s as a developer for a short while to setup the CSS and other customisations - if for you using Dev Tools is an issue then you can expose the ID’s via CSS and HTML Customizations added to </body> like this one:

<script>
if (window.jQuery) {
    window.jQuery(function ($) {
        var PageTracker = require('discourse/lib/page-tracker').default,
            updateCategory = function () {
                $('.categories .category h3').each(function( index ) {
                    var h = $( this );
                    h.append( ' - ' + h.parent().closest('tr').data('category_id') );
                });  
            };
        PageTracker.current().on('change', function (url) {
            setTimeout(function () {
                updateCategory();
            }, 100);
        });

    });
}
</script>

You can see a screen grab of the kind of output here:

After you are done with your CSS customisations I would recommend then turning this customisation off.

3 „Gefällt mir“