List articles by labels on the Article page / modify Related articles using labels | The place for Zendesk users to come together and share
Skip to main content
June 29, 2018
Question

List articles by labels on the Article page / modify Related articles using labels

  • June 29, 2018
  • 19 replies
  • 90 views

I'd like to use one article in more than one group of articles - for example, several different products use the same setting and I don't want to have the same content multiple times (and updating it multiple times when needed).

But at the same time, I would like to display all articles for one product on one page. An article cannot have more than one section/category and I didn't find a way to tweak Related articles, so it seems the Labels are the only way.

My goal is to:

1. add 'Product1', 'Product2' labels to the "Settings" Article

2. add label 'Product1' to "Product1 into" article and label 'Product2' to "Product2 intro" article (etc)

3. When a user opens "Product1 into" there will be a list of all articles (clickable titles) with label 'Product1' (and vice versa for "Product2 intro")

4. If a user opens the "Settings" Article, there will be two lists for each label.

I tried Curlybars but I didn't get very far.

 

 

 

19 replies

May 6, 2019

It seems zendesk changed the behavior of API "articles/search.json" and now returns wildcard search

Now I'm using article API with parameter label_names

https://developer.zendesk.com/rest_api/docs/help_center/articles

/api/v2/help_center/{locale}/articles.json?label_names=TM_family
May 7, 2019

Angeli,

It seems you would have to write a function that called the ZD APIs twice- once to get the labels of the current article, and the second time to search for all articles containing the same labels (if if getting a list of articles that share labels is what you were looking to do).

I had a hard time trying to figure out how to get the labels of the article currently loaded but I think I would do it like-

var currentArticleID = location.href  (insert a bunch of js work to parse out the id)

then api/v2/help_center/en-us/articles/<insert id from var here>.json would get you the current article from which you can get the label_names property. 

then /api/v2/help_center/articles/search.json?label_names=<labels from current article, comma separated> would give you list of "related" articles

 

Trapta11
May 7, 2019

Hi @Charles Lloyd,

You can use the below code and put it at the top of your article_template.hbs file:

<script>
var labels = [];
{{#each article.labels}}
labels.push('{{identifier}}');
{{/each}}
var apiURL = '/api/v2/help_center/articles/search.json?label_names='+labels.join(',');
console.log(apiURL); // Console the API Url
</script>

This will give you the API URL with labels of current articles. You can further call the ZD API to get the articles.

Let me know if this solves your issue.

Team Diziana

May 7, 2019

Hi @Diziana, 

Thanks much for the detailed code. I'm a total newbie to Curlybars and appreciate the example of accessing in-page properties. 

I'll post back here with a screenshot when I get a chance to implement this. 

September 6, 2019

Hi all, 

I finally implemented my solution that shows a list of Related Article if articles share the same label. Thanks for starter code and examples, Trapta and Katerina.

I put this in article_page.hbs-

<script>
var articleId = {{article.id}}
function showRelatedLinks(){
var labels = [];
{{#each article.labels}}
labels.push('{{identifier}}');
{{/each}}
var apiURL = '/api/v2/help_center/articles/search.json?label_names='+labels.join(',');
console.log(apiURL); // Console the API Url
console.log(labels);
return apiURL;
}
</script>

and then this in my script.js, make ajax call and do formatting work (also exclude the currently loaded article)-

//Show related links in right pane
//related links are articles that share one or more labels
function insertRelLinks(){
var template_start = `<ul class="section-articles__list">`;
var template_end = `</ul>`;
var template = ``;
var jqxhr = $.ajax( showRelatedLinks() )
.done(function( data ) {
if( data.count > 0 ){
$('#rellinks-section').html((template_start + template + template_end));
$.each( data.results, function( k, v ){
var vID = $(v.id);
if(vID[0]!==articleId) //don't show link to currently loaded article
{
template += `<li class="section-articles__item">
<a href="${v.html_url}" class="section-articles__link">${v.name}</a>
</li>`;
}
} );
$('.related-articles').show();
$('#rellinks-section').html((template_start + template + template_end));
}
});
}
insertRelLinks();

It looks like-

Nicole44
September 30, 2022

Hi @charles35, I love what you've done, I suck at coding but I'm trying to apply your code on my zendesk guide but i had no success. Is it anything else that i've might be missing?

Greg K
Employee
September 30, 2022

Hey Nicole! I can't say for sure, since I'm not familiar with his code, but there is a possibility that you're on the newer version of our help center templating, which removes jquery support. You can import it yourself, just take a look at this article for more information.

Fran11
November 29, 2024

Hi all, I'm trying to do something similar: I would like to have a collection of URL's  of articles which have the same label(s) shown in an “collection” article body. Everytime an article is created within the KB, with the same label, it will automatically be added to this “collection” article.
This setup should be used in multiple “collection” articles but with different labels per “collection” article, so that each “collection” article shows its own list of URLs to articles which have the same label. Through this we can show the same article URL which has multiple labels in multiple “collection” articles.
I have to assume you then need to add different code into each “collection” article to show articles with certain label(s), next to adding some code in *hbs / *.js files?
Has anybody tried this and can give code examples? many thanks!

Elaine14
Employee
October 31, 2025
Hi F. Keijmes,
 
That’s a great question — you’re thinking in the right direction! You can achieve this by using the Help Center API to dynamically pull articles by label and render them in your “collection” articles. You’ll basically need a script placed within your article or template that fetches all articles with specific labels, then loops through them to output the titles and links.
 
Here’s the general approach:
 
  1. Use the Help Center API endpoint:

     

    /api/v2/help_center/articles.json?label_names=your-label-here

    You can add multiple labels separated by commas.

     

  2. Include a small script in your article template (or collection article) to call this endpoint, parse the returned data, and display clickable links.

     

  3. Repeat for each “collection” article, changing the label(s) as needed. This way, each page dynamically lists only the related articles that share the same labels.

     

You don’t need to hardcode anything into your *.hbs files unless you want to globally change layouts — a small JavaScript snippet in the article footer or custom block can do the job.