Ricerche recenti


Nessuna ricerca recente

List all articles for each section(s) on the same category page



Data ultimo post: 16 feb 2016

Hi there,

Zendesk Component Reference: Category with section and article list.

Background: On category page when we have more articles (more than 6) for each section/sections, then there exist a "See all link" that would take you to the main section page in order to list/show all its articles.

We have used existing Zendesk component and add a capability (JS) through which we can pull/list all the article for the section on the same category page. (without redirecting users to the main section page). Whenever user click "See all link", the next set of the articles would appear.

How to do it:

  • Add below JS to the JS section of HC:
$(document).ready(function(){

/**
@add your hc domain here
@for eg: var hc_url = 'https://testcompany.com'
*/
var hc_url = 'Your_HC_URL'

var _allarticles = [],
_sorted = [],
_artHtml = '',
_id,
_url;

var _articles = function(article){
$.ajax({
url: _url,
type: 'GET',
dataType: 'json',
success: article
});
};

// function for see all articles button in category
$('.see-all-articles').click(function(e){
e.preventDefault();
_id = $(e.target).attr('href').split('/sections/')[1].split('-')[0];

if(typeof HelpCenter.user.locale == 'undefined') {
HelpCenter.user.locale = window.location.pathname.replace('/', '').replace('?', '/').split('/')[1];
}

_url = hc_url+'/api/v2/help_center/'+HelpCenter.user.locale+'/sections/'+_id+'/articles.json';
_articles(function(data){
_allarticles = data.articles;

if(data.count>30){
for(var i = 1; i<data.page_count; i++){
_url = data.next_page;
_articles(function(data){
_allarticles = _allarticles.concat(data.articles);
_arthtml = '';
$(_allarticles).each(function(idx, itm){
if(itm.draft==true){
} else {
_arthtml = _arthtml + '<li class="'+(itm.promoted==true?'article-promoted':'')+'"><span data-title="Promoted article" style="'+(itm.promoted==false?'display:none':'')+'">★</span><a href="'+itm.html_url+'">'+itm.title+'</a></li>';
}
});
$(e.target).parent().find('ul.article-list').html(_arthtml);
$(e.target).hide();
})
}
} else {
_arthtml = '';
$(data.articles).each(function(idx, itm){
if(itm.draft==true){
} else {
_arthtml = _arthtml + '<li class="'+(itm.promoted==true?'article-promoted':'')+'"><span data-title="Promoted article" style="'+(itm.promoted==false?'display:none':'')+'">★</span><a href="'+itm.html_url+'">'+itm.title+'</a></li>';
}
});
$(e.target).parent().find('ul.article-list').html(_arthtml);
$(e.target).hide();
}

});
});
// function for see all articles button in category ends here

});

 




  • There is a variable named var_hc, add your Zendesk URL there.

            for an e.g: var_hc='https://support.zendesk.com'

  • Save and publish the changes.
  • Click see all articles link.

Let us know if you face an issue.

Cheers,

Diziana

 

 


0

49

49 commenti

Tipene Hughes Yes! This is great thank you.

0


Hey Noel Hayden,

Here's a similar thread which you might find helpful: 

https://support.zendesk.com/hc/en-us/community/posts/4865868866586-Show-all-articles-on-Category-page-for-Zendesk-Guide-Help-Centre

Let me know if you have any questions!

Tipene

0


I am still confused. I am looking for a way show show all the articles under a section on the category page when the category page first loads (don't have to click anything on the page). It seems there is an article here: https://support.zendesk.com/hc/en-us/community/posts/4409506679962#community_comment_360000010847 the references how to show less than 6 (the default amount) but just showing more does not seem possible. It looks like Jeremy Tellier earlier in the thread alluded to the same question and that he solved it but the solution was unclear. Can anyone tell me how to do this? (The code on this thread originally seems to be focused on showing all the articles once you click but not all by default.)

1


Hey Anusha,

It may be worth taking a look at the following documentation to see if that points you in the right direction:

I hope this helps!

0


Hi! My website currently lists articles under section but we recently added subsections to our website. Is there any way we can display articles in subsection as a dropdown or in some other format in our category page via code edits. Something like this:

Category Name

Section name

Subsection name

  • articles in subsection

0


Hi Kay, thank you for your help. Yes, I understand it and try to modify the script. I'm not so cool in the JS, so that is why I ask to share a solution about it. In any case, If someone already did it,  please share.

0


I am sorry I didn't see it was this article 🙈

You'll need adjust this script from above a little bit.
Instead of doing the API call on user click, you'll want to fetch on load, and cycle through all sections, and get its articles.

I don't have an exact sample script for that, but here's how that could work

- Execute script on page load
- Find section IDs of current category
- Loop through those sections and get the articles for that section and add article links to the DOM

0


Hi 990965883. I'm a little confused. You provided the link "awesome tip" on the current article. I already applied the solution from the current article in my Zendesk theme, and it works great (images below). But my question was about displaying all articles from a section on a category page without clicking on the button "see all articles." The same question was from @Angeli Ho above. 

 

 

0


Danila Slezko Check out the awesome tip on how to do that from Ifra Saqlain

0


Hi all, someone knows how to show all articles on the category page without clicking on the "See-All-Articles" for this article's solution.

If anyone knows how to do this, please share it. I think it will be very useful for everyone, especially considering that in the Zendesk theme app v.2 {{section_tree_with_articles}} and {{categor_tree_with_articles}} does not work.

0


Accedi per aggiungere un commento.

Non hai trovato quello che cerchi?

Nuovo post