Tutorial: CGBlog + JSON-LD Markup

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Locked
User avatar
creopard
Forum Members
Forum Members
Posts: 47
Joined: Fri Nov 10, 2017 10:25 am
Location: .de
Contact:

Tutorial: CGBlog + JSON-LD Markup

Post 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 :)
ransen
New Member
New Member
Posts: 1
Joined: Thu Mar 14, 2019 9:23 am

Re: Tutorial: CGBlog + JSON-LD Markup

Post by ransen »

Thanks for this tutorial. I work with data JSON-LD now.
Locked

Return to “Tips and Tricks”