Implementing FAQPage Schema in tag page.
-
November 13, 2020 at 10:47 pm #4502[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.
November 14, 2020 at 7:51 am #4503BobDo you want to check if there is the last post to remove the comma from the JSON-LD?
November 14, 2020 at 6:55 pm #4515[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!!
November 14, 2020 at 7:24 pm #4516BobTry 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>
November 15, 2020 at 6:58 pm #4527[anonymous]Cool. Thanks!
I will pinging on this later tonight.
Cheers!!
November 17, 2020 at 5:04 pm #4541[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!!
November 17, 2020 at 5:13 pm #4542BobUntil 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/
November 17, 2020 at 5:54 pm #4543[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,
- the post-qa.hbs to add the FAQPage code for that specific post — and that works fine
- 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…
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.
- 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.
- 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.
November 17, 2020 at 6:03 pm #4546BobThe 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-helperMost likely you have a problem with the wrong context on the tag page right now.
November 17, 2020 at 6:23 pm #4547[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.
November 18, 2020 at 9:00 pm #4565[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.