Page 1 of 1

Tutorial: CGBlog + JSON-LD Markup

Posted: Wed Mar 13, 2019 9:49 am
by creopard
Just a quick hack:

For displaying JSON-LD data for Google SERPS,
https://developers.google.com/search/do ... es/article

I added following coding to the detail template of the CGBlog module:

Code: Select all

{strip}
<__script__ type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "mainEntityOfPage": {
    "@type": "WebPage",
    "@id": "{$entry->canonical}"
  },
  "headline": "{$entry->title|escape}",
  "image": [
  {if $entry->fieldsbyname.image->type=='image'}
    {foreach from=$entry->fields item='field'}
        {if $field->type == 'image'}
          "{$entry->file_location}/{$field->value}"
          {if not $field@last}, {/if}
        {/if}
    {/foreach}
  {else}
  "https://www.example.com/altrernative_image.png"    
  {/if}
   ],
  "datePublished": "{$entry->postdate}",
  "dateModified": "{$entry->modified_date}",
  "author": {
    "@type": "Person",
    "name": "{$entry->author}"
  },
  "publisher": {
  "@type": "Organization",
  "name": "{$entry->author}",
    "logo": {
    "@type": "imageObject",
    "url": "https://www.example.com/logo.png"
    }
  }
}
</__script>
{/strip}
Use <__script__ ... > without underline, unlike above!

Have fun :)

Re: Tutorial: CGBlog + JSON-LD Markup

Posted: Thu Mar 14, 2019 9:33 am
by ransen
Thanks for this tutorial. I work with data JSON-LD now.