Skip to main content
Version: Fegg 5.x

JsonLd::article

An article: a news post, a blog post

Description​

public static array JsonLd::article( array $data [, string $type = 'NewsArticle' ] )

Returns an article item. The keys below are converted; any other key is kept as it is. Empty values are left out.

Throws \InvalidArgumentException when a date cannot be read.

Arguments​

NameData typeDefaultRemarks
$dataarraySee below
$typestring'NewsArticle''NewsArticle', 'BlogPosting' or 'Article'

Data​

KeyValueWritten as
headlineThe titleAs it is
datePublished'Y-m-d H:i:s' from the database, a Unix time or a date objectISO 8601 with the time zone
dateModifiedThe sameISO 8601 with the time zone
imageA path or URL, or a list of themA list of absolute URLs
urlPath of the pageAn absolute URL
authorA name{"@type": "Organization", "name": ...} (an array is kept as it is)
publisherA nameThe same

Example​

Controller
use Fegg\Tool\JsonLd;

JsonLd::article(array(
'headline' => $data['title'],
'datePublished' => $data['post_date'],
'dateModified' => $data['modified'],
'image' => $data['image_id'] ? FEGG_CURRENT_DOMAIN . getImageUrl($data['image_id']) : '',
'url' => '/blog/' . $data['blog_id'] . '/',
'author' => array('@type' => 'Person', 'name' => $data['writer']),
'publisher' => 'Example Inc.',
), 'BlogPosting');

getImageUrl() returns a path that already contains the base path, so only the domain is added (see Absolute URLs).