MENU

Automatically send a featured article to social media

  Previous article Next article  

Select a random CGBlog article and post it once a day to the social media using IFTTT.

  How to use

1. Create a new CGBlog summary template named "cgblog_featured_feed", using the following content:

{strip}
{$current_date = $smarty.now|date_format:'%d'}
{$stored_date = "{get_site_preference('featured_cgblog_stored_date','')}"}

{$featured_cgblog_id = "{get_site_preference('featured_cgblog_id','')}"}

{if $current_date != $stored_date}
  {capture}{$items|@shuffle}{/capture}
  {foreach from=$items item=entry}
    {if $entry->id != $featured_cgblog_id}
      {set_site_preference('featured_cgblog_description',"{$entry->summary|strip_tags:false|escape|strip|truncate:150}")}
      {set_site_preference('featured_cgblog_id',"{$entry->id}")}
      {set_site_preference('featured_cgblog_url',"{$entry->fieldsbyname.short_url->value|default:$entry->detail_url}")}
      {set_site_preference('featured_cgblog_title',"{$entry->title|escape}")}
      {break}
    {/if}
  {/foreach}
  {set_site_preference('featured_cgblog_stored_date',"{$smarty.now|date_format:'%d'}")}
{/if}

{$featured_cgblog_description = "{get_site_preference('featured_cgblog_description','')}"}
{$featured_cgblog_id = "{get_site_preference('featured_cgblog_id','')}"}
{$featured_cgblog_title = "{get_site_preference('featured_cgblog_title','')}"}
{$featured_cgblog_url = "{get_site_preference('featured_cgblog_url','')}"}

{/strip}<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<atom:link href="{root_url}/feed-featured.rss" rel="self" type="application/rss+xml" />
<title>{sitename}</title>
<link>{root_url}</link>
<description>Featured Article from {sitename}</description>
<copyright>{sitename}</copyright>
<generator>CMS Made Simple</generator>
  <item>
    <title>{$featured_cgblog_title}</title>
    <description>{$featured_cgblog_description}</description>
    <guid>{$featured_cgblog_url}</guid>
    <link>{$featured_cgblog_url}</link>
  </item>
</channel>
</rss>
{*
+++ NOTE When stop using this feature, clean up the system by loading these lines once! +++
{remove_site_preference('featured_cgblog_description')}
{remove_site_preference('featured_cgblog_id')}
{remove_site_preference('featured_cgblog_stored_date')}
{remove_site_preference('featured_cgblog_title')}
{remove_site_preference('featured_cgblog_url')}
*}

2. Create a new User Defined Tag named "content_type"

content_type
$content_type = get_parameter_value($params,'type');
if ($content_type != '') { cmsms()->set_content_type($content_type); }

3. Create in Design Manager a new Core::Page Template named "blank", that only contains:

{content wysiwyg=false}

4. Create a new content page "Feed Featured". In the options tab of the page editor you must use the new Core::Page template "blank" and set the page non-searchable, not in menu and WYSIWYG switched off!
In the page content you put:

{content_type type='application/rss+xml'}
{CGBlog summarytemplate='cgblog_featured_feed'}

Set in options tab Page URL: feed-featured.rss

You can test your feed at www.website.com/feed-featured.rss The random featured CGBlog article will be changed once a day at this RSS feed.

Attach this feed to IFTTT.com and use it to post to Twitter or another social media platform of your choice.


5. More!
Because the featured article data is stored in a core site preference, we can also read it at other place at the website. Some examples:

{$featured_cgblog_description = "{get_site_preference('featured_cgblog_description','')}"}
<p>The featured CGBlog description is: {$featured_cgblog_description}</p>

{$featured_cgblog_id = "{get_site_preference('featured_cgblog_id','')}"}
<p>The featured CGBlog ID is: {$featured_cgblog_id}. You could use this like:</p>
{if $page_alias == 'home'}
  {$page_image = "{CGBlog action='detail' detailtemplate='cgblog_featured_detail' articleid=$featured_cgblog_id}"}
{/if}

{$featured_cgblog_title = "{get_site_preference('featured_cgblog_title','')}"}
<p>The featured CGBlog title is: {$featured_cgblog_title}</p>

{$featured_cgblog_url = "{get_site_preference('featured_cgblog_url','')}"}
<p>The featured CGBlog URL is: {$featured_cgblog_url}</p>

I used this at the homepage of the CMS Made Simple Showcase


  Working example



  Show related articles:


  Comment Form

Click here to open the form


  0 Comments

No comments yet...

CMS Made Simple - Tutorials, tips and tricks - CMSMS

Automatically send a featured article to social media

  Article optimized for CMSMS 2.x

  Author:
  Last tested in: CMSMS 2.2.8
  Last updated: 23-07-2018
  Comments: 0
  http://cms.ms/pflO

Advertisement



Ads help me to help you! Thanks!

Ads help me to help you! Thanks!

Ads help me to help you! Thanks!