Recent searches


No recent searches

Show category name in promoted article.



Posted Mar 10, 2022

Hi, 

Currently I have a div element, with the promoted article URL, I was wondering is there away to display the category that specific promoted article belongs to.

 


0

6

6 comments

image avatar

Ifra Saqlain

Zendesk LuminaryMost Engaged Community Member - 2022Most Engaged Community Member of The Year - 2021Community Moderator

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


Thanks Ifra, it worked!

0


image avatar

Ifra Saqlain

Zendesk LuminaryMost Engaged Community Member - 2022Most Engaged Community Member of The Year - 2021Community Moderator

Awesome :)

0


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


image avatar

Ifra Saqlain

Zendesk LuminaryMost Engaged Community Member - 2022Most Engaged Community Member of The Year - 2021Community Moderator

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


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.

Didn't find what you're looking for?

New post