Show category name in promoted article.

6 Comments

  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    Hello Ayub Mohamud,

    I made the  below code for the home_page.hbs file means for homepage. You can see the below code.

    <div class="container">
    {{#each categories}}
    <h1><a href="{{url}}">{{name}}</a></h1><br>
    {{#each sections}}
    {{#if articles}}
    {{#each articles}}
     {{#if promoted}}
    <ul><li><a href="{{url}}">{{title}}</a></li></ul><br>
    {{/if}}
    {{/each}}
    {{/if}}
    {{/each}}
    {{/each}}
    </div>


    Screenshot:





    Output: In the given screenshot, a category with the promoted articles.


     

     

    If any query do let me know :)

     

    Thanks

    Ifra

     

    0
  • Ayub Mohamud

    Thanks Ifra, it worked!

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    Awesome :)

    0
  • Joshua Barnard

    Hi Ifra Saqlain,

    How do you account for categories with zero promoted articles?

    Not all of my categories have promoted articles, so there ends up being a few headings without any articles under them.

    Thanks,

    Josh

    0
  • Ifra Saqlain
    Community Moderator
    Most Engaged Community Member of The Year - 2021

    Hey Josh,

    you can use the code below to show all articles inside the category on the homepage:

    <div class="container">
    {{#each categories}}
      <section>
    <h3>
    <a href="{{url}}"> {{name}} </a>
    </h3>
    <ul>
    {{#each sections}}
    {{#if articles}}
    {{#each articles}}
      <li>
    <a href="{{url}}">{{title}}</a>
    {{#if promoted}}
    <a href="{{url}}">{{title}}</a>
    {{/if}}
    </li>
    {{/each}}
    {{/if}}
    {{/each}}
    </ul>
    </section>
    {{/each}}
    </div>

     

     

    Thanks :)

    Team

     

    0
  • Joshua Barnard

    Hi Ifra Saqlain,

    I appreciate the response. Unfortunately, that solution does not achieve the desired result. If a category contains no promoted articles, it shows the category name only. 

    I worked around it by adding some JavaScript to detect empty sections and remove them.

    Thanks,

    Josh

    0

Please sign in to leave a comment.

Powered by Zendesk