Sign in

Get posts by main tag

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2537
    rjcpereirarjcpereira

    I’ve some sections in the homepage, each one has a number of posts by tags, but if one post have more than one tag, it appears on several sections.

    In order to avoid add an additional argument exclude_tags or main_tag on {{#getPostsByTags}} helper, i suggest create an {{#getPostsByMainTag}} helper.

    I think that if the pages-feature came to reality, this is no longer necessary.

    #2575
    rjcpereirarjcpereira
    let themeHelpers = {
        getPostsByMainTag: function(mainTag, content) {
    
            const postsData = JSON.parse(JSON.stringify(content.data.website.contentStructure.posts));
    
            let filteredPosts = [];
    
            postsData.forEach(function(post) {
    
                post.mainTag.slug == mainTag && filteredPosts.push(content.fn(post));
            });
    
            return filteredPosts.join();
        }
    };
    module.exports = themeHelpers;
Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘Get posts by main tag’ is closed to new replies.