header based on category_id

Technical Support
  • hi guys,

    recently I have tried to create a script that displays a random image in a folder as a header image. however, I cam across some problems.

    first we can add an image to the custom header like so:

    <img src=<!-- url image--> class='center'>
    

    then add css to custom css like so

    img.center {
        display: block;
        margin-left: auto;
        margin-right: auto
    }
    

    however, i want to only show the image on a certain category. so I tried this for category 1:

    <script>
    $(window).on('action:ajaxify.contentLoaded', function(){
      if (ajaxify.data && ajaxify.data.cid && ajaxify.data.cid === 1) {
            <!-- insert html image-->
      }
    });
    </script>
    

    nothing happens.

    Can anybody guide me on how to display an header-image when in a certain category?

    Thank you,

  • What version of NodeBB and where did you place the custom javascript code?

    Maybe try

    <script>
    $(window).on('action:ajaxify.end', function(){
      if (ajaxify.data && ajaxify.data.cid && parseInt(ajaxify.data.cid, 10) === 1) {
            <!-- insert html image-->
      } else {
           <!-- remove html image -->
      }
    });
    </script>
    

    Put some console.logs in there to make sure the expected code is being executed.


Suggested Topics