Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

Implementing FAQPage Schema in tag page.

  • #4502
    Avatar photo[anonymous]

    I am thinking of using a tag page for FAQs and would like to implement the FAQPage Schema. Most of what I need is relatively straight forward. In order to implement the schema code I would need to know if/or when I am processing the last post without consideration to the number of posts per pagination. In otherwords, I would need to continue with pagination in generating the HTML, however, would need to process all posts on the first page for FAQPage and specifically know when I am processing the last post.

    The only thing I see that appears to be helpful is @pagination.totalPosts – total number of posts.

    Any help or clues would be appreciated.

    #4503
    Avatar photoBob

    Do you want to check if there is the last post to remove the comma from the JSON-LD?

    #4515
    Avatar photo[anonymous]

    Basically – that’s it. There are some changes in the code for the last couple of lines. I just need to be able to know when I get to the end.

    If I can crack that nut, I will worry about the rest after some poking around.

    Cheers!!

    #4516
    Avatar photoBob

    Try this one:

    <script type="application/ld+json">
             {
             "@context": "https://schema.org",
             "@type": "FAQPage",
             "mainEntity": [ 
             {{#each posts}}
                {{#checkIf @index '>' 0}}, {{/checkIf}}
                {
                   "@type": "Question",
                   "name": "{{title}}",
                   "acceptedAnswer": {
                   "@type": "Answer",
                   "text": "{{{ excerpt }}}"
                   }
                }
             {{/each}} 
             ]}
          </script>
    #4527
    Avatar photo[anonymous]

    Cool. Thanks!

    I will pinging on this later tonight.

    Cheers!!

    #4541
    Avatar photo[anonymous]

    I am trying to reply to this post with specific details but cannot. I am getting…

    Block Reason: A potentially unsafe operation has been detected in your request to this site

    I did use Code Insert to include the code I used and that may have been the reason why I was blocked. I tried again using the word “redacted” for the code term I suspected it was hitting on — I won’t repeat it here – JIC.

    Is there a safe way to include the code? I could, I suppose, make an image of it.

    Can you help??

    Cheers!!

    #4542
    Avatar photoBob

    Until now we did not have too many such requests, so I think that the security settings are ok.  Anyway, yo can share with us a link to your code posted e.g.  on the Codepen https://codepen.io/

    #4543
    Avatar photo[anonymous]

    I edited the config.json and created a post-qa.hbs and tag-qa.hbs file for questions and answers (aka FAQs). Each works as you would expect.

    I have edited both,

    1. the post-qa.hbs to add the FAQPage code for that specific post — and that works fine
    2. the tag-qa.hbs to add the FAQPage code for all FAQ/Q&A posts — and that fails

    For the tag-qa.hbs file, I have tried both…

    https://codepen.io/codepen-slpa/pen/oNLOxOz

    and

    https://codepen.io/codepen-slpa/pen/NWrmrKL (I reedited this for this post and hopefully I did it right)

    and get…

    https://codepen.io/codepen-slpa/pen/OJXGXPZ

    which shows like this…

    example

    The code that is created looks fine to me except that I only get one of the three test QA/FAQs…

    So I have two problems now.

    1. The code I created for the tag page is not cycling through all of the posts on the FAQ tag page — I get just one.
    2. The HTML code is somehow broken and I cannot see the reason why at this point.

    I did notice that Publii removes the formatting/tabs/new line of the page except for my code — I wondered if this could be a part of the problem.

    I looked at this last night and could not see the problems. I am sure they are staring me in the face! I will look at it again tonight for anything amiss.

    Cheers for your help.

    #4546
    Avatar photoBob

    The code from my previous message should be embedded in the head.hbs file
    Then you can control where it is displayed by {{is}} helper https://getpublii.com/dev/is-helper/#is-helper

    Most likely you have a problem with the wrong context on the tag page right now.

    #4547
    Avatar photo[anonymous]

    Cheers!!

    I will modify my work tonight or tomorrow morning and see what I can come up with. I am a semi-retired technologist and a landlord by day. I have to get an apartment ready for a new tenant or I would ping on this right now. 😉

    Thanks for your quick replies.

    #4565
    Avatar photo[anonymous]

    Thanks for all of your guidance!

    For the sake of all those who read this, here is what I did.

    I copied the partials/head.hbs and pasted it to partials/head-qa.hbs. You can use what name you want of course.

    I copied the tag.hbs and pasted it to tag-qa.hbs. You can use what name you want of course.

    In tag-qa.hbs, I changed…

    {{> head}}

    to…

    {{> head-qa}}

    …to use the new header.

    I created a questions and answers tag.

    I set all question and answer posts to use the questions and answers tag and set the main tag to questions and answers.

    I then edited the head-qa.hbs file and just before the…

    </head>

    … I added the following code https://codepen.io/codepen-slpa/pen/jOrRjKo

    I am not sure if I should also do this for each post. I just might. Any advice on this is appreciated.

    It may suffice to just include the FAQPage Schema to the Questions and Answers tag page.

    Cheers!!

    Mods: It may be a good idea to include the code pen code directly in this post in case it gets lost. If you can, please do so.