DiscussionForumPosting schema implementation

Has anyone done anything with the DiscussionForumPosting schema yet?
Had it on my site for a while.
Add this at the bottom of template thread_view ...
HTML:
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "DiscussionForumPosting",
  "@id": "{xen:link 'canonical:threads', $thread}",
  "headline": "{xen:jsescape $thread.title}",
  "articleSection": "{xen:jsescape $forum.title}",
  "dateCreated": "{xen:jsescape '{xen:date $thread.post_date, 'Y-m-d'}'}",
  "dateModified": "{xen:jsescape '{xen:date $thread.last_post_date, 'Y-m-d'}'}",
  "image": "{xen:jsescape @headerLogoPath}",
  "author": {
    "@type": "Person",
    "name": "{xen:jsescape $thread.username}"
  },
  "url": "{xen:link 'canonical:threads', $thread}",
  "interactionStatistic": {
    "@type": "InteractionCounter",
    "interactionType": "https://schema.org/ReplyAction",
    "userInteractionCount": "{xen:calc "{$totalPosts} - 1"}"
  }
}
</script>
 
Datecreated and modified can be changed to j-M-Y for example?

Tested it in google testing tool and changing date works. But i get an error for image and datePublished

For image you have to fill in full url for logo on your style, that fixed it. And datePublished has to be added. This would be the same as dateCreated?

"datePublished": "{xen:jsescape '{xen:date $thread.post_date, 'j-M-Y'}'}",

Strangly enough that gives error and date format has to be Y-m-d


On xenforo 2 you also get some errors. For image you could also use the avatar from OP.

https://search.google.com/structured-data/testing-tool?hl=nl#url=https://xf2demo.xenforo.com/threads/whats-the-correct-way-to-insert-update-and-delete.3273/
 
Last edited:
Did some changes for a correcter format, only have to find articleBody (first post)

dateCreated is not necessary because datepublished is required and the same.

url is also same as id, so removed url.

Code:
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "DiscussionForumPosting",
  "@id": "{xen:link 'canonical:threads', $thread}",
  "headline": "{xen:jsescape $thread.title}",
  "articleSection": "{xen:jsescape $forum.title}",
  "articleBody": "{xen:jsescape $???}",
  "datePublished": "{xen:jsescape '{xen:date $thread.post_date, 'Y-m-d'}'}",
  "dateModified": "{xen:jsescape '{xen:date $thread.last_post_date, 'Y-m-d'}'}",
  "image": "{xen:jsescape @headerLogoPath}",
  "author": {
    "@type": "Person",
    "name": "{xen:jsescape $thread.username}"
  },
  "interactionStatistic": {
    "@type": "InteractionCounter",
    "interactionType": "https://schema.org/ReplyAction",
    "userInteractionCount": "{xen:calc "{$totalPosts} - 1"}"
  }
}
</script>
 
Last edited:
Did some changes for a correcter format, only have to find articleBody (first post)

dateCreated is not necessary because datepublished is required and the same.

url is also same as id, so removed url.
Oh, you're right on DatePublished - never picked that up some months back when I implemented. Best to leave url reference too, since some use it in preference to the @id
Here it is with articleBody and avatar for image...
Code:
<script type="application/ld+json">
{
  "@context": "http://schema.org",
  "@type": "DiscussionForumPosting",
  "@id": "{xen:link 'canonical:threads', $thread}",
  "headline": "{xen:jsescape $thread.title}",
  "articleSection": "{xen:jsescape $forum.title}",
  "articleBody": "{xen:jsescape '{xen:helper snippet, $firstPost.message, 255}'}",
  "datePublished": "{xen:jsescape '{xen:date $thread.post_date, 'Y-m-d'}'}",
  "dateModified": "{xen:jsescape '{xen:date $thread.last_post_date, 'Y-m-d'}'}",
  "image": "{xen:jsescape '{xen:helper avatar, $thread, m, 0, 1}'}",
  "author": {
    "@type": "Person",
    "name": "{xen:jsescape $thread.username}"
  },
  "url": "{xen:link 'canonical:threads', $thread}",
  "interactionStatistic": {
    "@type": "InteractionCounter",
    "interactionType": "https://schema.org/ReplyAction",
    "userInteractionCount": "{xen:calc "{$totalPosts} - 1"}"
  }
}
</script>
 
Thx ;)

Any idea why the date format for dateModified can be changed but not of datePublished?

Also is dateModified correct to add? Because this does not point to first post modification but when a new post is added.
 
Last edited:
articleBody changes depending on the page (first post of that page).

But author, datePublished and image does not. Shouldn't that change also depending on the page, same for url?
 
Top Bottom