Post
A post is one item fetched from a social media provider, such as a tweet, an Instagram photo or a YouTube video. Whenever you’re dealing with a post in your template, you’re working with a Post object. Each provider returns different content, and a Post normalises it so the same template works for every source. The raw response from the provider’s API is always available through data.
craft.socialFeeds.getPosts() returns an array of posts for a feed, and source.getPosts() returns them for a single source.
{% for post in craft.socialFeeds.getPosts('homepage', { limit: 10 }) %}
<a href="{{ post.url }}">
{{ post.getContent() }}
</a>
{% set image = post.getImage() %}
{% if image %}
<img src="{{ image.url }}" alt="{{ image.alt }}">
{% endif %}
{{ post.author.name ?? '' }} · {{ post.getFriendlyDate(post.dateCreated) }}
{% endfor %}
Properties
The post’s ID on the provider, such as a YouTube video ID.
The provider’s unique identifier for the post item. For most providers this matches id.
The post’s title, for providers that give posts one, such as YouTube or a Facebook event. This is null for most posts.
The post’s main text or description, as plain text.
The URL of the post on the provider’s site.
The ID of the source the post was fetched from.
The handle of the source the post was fetched from.
The handle of the source’s provider, such as instagram or youTube.
The kind of post, for providers that classify them, such as image, video, reel or event. The values depend on the provider, and this is null when the provider doesn’t classify posts.
The number of likes the post has, or null when the provider doesn’t report it.
The number of shares the post has, or null when the provider doesn’t report it.
The number of replies or comments the post has, or null when the provider doesn’t report it.
The date the post was published on the provider.
The date the post was last updated on the provider, when the provider reports it.
The Post Author who published the post, or null when the provider doesn’t supply one.
The post’s tags or hashtags, as strings.
The Post Link objects attached to the post.
The image Post Media objects attached to the post.
The video Post Media objects attached to the post.
The full, unaltered response for the post from the provider’s API. Use it for content Social Feeds doesn’t normalise.
Any extra provider-specific values Social Feeds keeps alongside the post.
Methods
Returns the class name of the source type that fetched the post, such as verbb\socialfeeds\sources\YouTube, or null when that type is no longer registered. Use sourceHandle to look up the source itself.
Returns the display name of the post’s provider, such as YouTube.
Returns the post’s main content, ready to output. This is the title when the post has one, otherwise the text, HTML-encoded.
Returns whether the post has at least one image or video.
Returns the author’s profile image as an array with url and alt keys, or null when there’s no photo.
Returns the post’s first image as an array with url and alt keys, or null when it has no images. The alt text names the author, provider and date.
Returns the post’s first video as an array with a url key, or null when it has no videos.
Returns: string
Returns how long ago a date was in short form, such as 5d or 3h.
Returns the brand colour of the post’s provider as a hex value.
Returns the icon of the post’s provider as SVG markup.