Blog Sections Open

Displaying Recent Instagram Images in Evolution CMS

Before modern social APIs became more locked down, a common request was to show recent Instagram images directly on a site. The original snippet behind this article pulled image data through the Instagram API and rendere

Before modern social APIs became more locked down, a common request was to show recent Instagram images directly on a site. The original snippet behind this article pulled image data through the Instagram API and rendered it through simple template placeholders.

Legacy Snippet Pattern

<?php
if (!defined('MODX_BASE_PATH')) {
    die('What are you doing? Get out of here!');
}

$access_token = isset($access_token) ? $access_token : 'your access token';
$user = isset($user) ? $user : 'user_id';
$outerTpl = isset($outerTpl) ? $outerTpl : '<div class="i-images">[+i.wrapper+]</div>';
$rowTpl = isset($rowTpl) ? $rowTpl : '<a href="[+i.href+]" target="_blank"><img src="[+i.src+]"></a>';

$inst = file_get_contents('https://api.instagram.com/v1/users/' . $user . '/media/recent/?access_token=' . $access_token);
$inst = json_decode($inst, true);

$out = '';
foreach ($inst['data'] as $data) {
    $out .= str_replace(
        array('[+i.href+]', '[+i.src+]'),
        array($data['link'], $data['images']['thumbnail']['url']),
        $rowTpl
    );
}

return str_replace('[+i.wrapper+]', $out, $outerTpl);

What Still Matters Today

  • keep API access outside the template layer
  • use row and outer templates so editors can change markup
  • cache responses where possible to avoid hitting remote APIs on every request
  • expect third-party API rules to change over time

Even if the old Instagram endpoint is no longer usable as-is, the architectural idea is still good: one small integration snippet, one output wrapper, and minimal logic in templates.

Modern Advice

For current projects, prefer the official provider APIs, scheduled imports, or a server-side cache layer. Treat social feeds as integrations, not as hard requirements for page rendering.

Source: original community announcement.

Newer post

Finding or Building a Module to Copy Multiple Resources at Once

How to think about bulk resource duplication in Evolution CMS and when a dedicated helper module is better than manual copying.

Older post

Improving the Manager Tree for Sites with Many Child Resources

A historical manager UX note on tree hacks designed for sections with large numbers of child documents.