homm/hommsocialfeed

juicer.io 的 Craft CMS 社交动态适配器

2.1.2 2022-09-21 08:34 UTC

This package is auto-updated.

Last update: 2024-09-21 14:09:38 UTC


README

HOMM Social Feed for Juicer

Screenshot

需求

此插件需要 Craft CMS 4.x。

关于 Craft CMS 3.x 插件版本,请参阅 1.x 标签。

安装

要安装插件,请按照以下说明操作。

  1. 打开您的终端并转到您的 Craft 项目

     cd /path/to/project
    
  2. 然后告诉 Composer 加载插件

     composer require homm/hommsocialfeed
    
  3. 在控制面板中,转到设置 → 插件,然后点击 HOMM 社交动态的“安装”按钮。

HOMM 社交动态概述

HOMM 社交动态是 juicer.io 的 Craft 适配器,用于收集您所有的社交媒体动态,以便轻松集成到您的应用程序中。

配置 HOMM 社交动态

转到 设置 > HOMM 社交动态 以设置基本配置选项

  • 社交动态 API 路径: 您的 Juicer API 路径(例如:https://www.juicer.io/api/feeds/artdecohotelmontana
  • 帖子数量: 默认查询的帖子数量
  • 颜色: 您可以为每个动态设置的颜色。这些值仅用于 CP 部分。在查询中检索到的值为 dark、highlight 和 muted。

添加以下 CronJob,以定期更新您的社交动态

/path/to/your/project/craft hommsocialfeed/social-feeds/update

使用 HOMM 社交动态

在左侧导航中选择 HOMM 社交动态

您可以设置以下属性

  • 状态: 禁用或启用特定帖子
  • 颜色: 更改或重置特定帖子的颜色
  • 隐藏图像/视频: 隐藏特定帖子的图像或视频

模板(Twig)中的基本用法

{% for socialFeed in craft.socialFeed.all() %}
    <img src="{{ socialFeed.image }}" alt="{{ socialFeed.message|slice(0, 10) }}" loading="lazy">
{% endfor %}

模板(Twig)中的复杂示例

{# Query all posts which has an image and the image is not hidden #}
{% for socialFeed in craft.socialFeed.all([{ isMediaHidden: false }, ['not', { image: null }]]) %}
    <div class="{{ socialFeed.color }}">
        {% if not socialFeed.isMediaHidden %}
            {% if socialFeed.video is not empty %}
                <div class="img">
                    <video class="video" controls poster="{{ socialFeed.image }}">
                        <source src="{{ socialFeed.video }}" type="video/mp4">
                    </video>
                </div>
            {% elseif socialFeed.image is not empty %}
                <a href="{{ socialFeed.feedUrl }}" title="{{ readMore }}" target="_blank">
                    <img src="{{ socialFeed.image }}" alt="{{ socialFeed.message|slice(0, 10) }}" loading="lazy">
                    <span>                             
                        {{ socialFeed.feedDateCreated|date('long') }}
                    </span>
                </a>
                {% for additionalPhoto in socialFeed.additionalPhotos|json_decode %}
                    <img src="additionalPhoto" alt="{{ socialFeed.message|slice(0, 10) }}" loading="lazy" style="display: none;">
                {% endfor %}
            {% endif %}
        {% endif %}
        {% if socialFeed.message is not empty %}
            <div>
                {% if socialFeed.message|length > 120 %}
                    {% set message = socialFeed.message|slice(0, 120) ~ '...</p>' %}
                {% endif %}
                {{ (message ?? socialFeed.message)|raw }}
                <a href="{{ socialFeed.feedUrl }}" title="{{ readMore }}" target="_blank">
                    {{ readMore }}
                </a>
            </div>
        {% endif %}
    </div>
{% endfor %}

craft.socialFeed.all() 函数接受以下参数

  1. (array) $conditions: 一组 where-/andWhere-条件(见上方示例)。
  2. (?int) $limit: 覆盖设置页面中提供的默认限制。
  3. (?array) $orderBy: 根据一个或多个列排序。默认为 ['homm_socialfeeds.feedDateCreated' => SORT_DESC]

HOMM 社交动态路线图

一些要做的事情和潜在功能的想法

  • 在 CP 部分添加筛选器
  • 允许将社交动态图像本地保存

HOMM interactive 提供