getgrav / grav-plugin-feed

Grav Feed Plugin
https://getgrav.org
MIT License
16 stars 12 forks source link

array_merge(): Argument #1 is not an array #13

Closed Quanatee closed 7 years ago

Quanatee commented 7 years ago

I hit a problem at this line:

// Overwrite regular content with feed config, so you can influence the collection processing with feed config $page->header()->content = array_merge($page->header()->content, $this->feed_config);

Which shows up this warning: E_WARNING - array_merge(): Argument #1 is not an array

Could I get some insight on what the issue might be?

briankelleher commented 7 years ago

This still happens to me on a fresh install.

Quanatee commented 7 years ago

@briankelleher I worked around this by not using the plugin at all. Made a template using twig. Works even better since I get to customize my own feeds now. This is a quickly watered down code that should work for stock grav. It will only reflect visible posts that are posted within the running week. Without that condition the feed will produce everything you have.

{% set collection = page.collection() %}
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title>{{ site.title }}</title>
        <link>{{ page.url(true) }}</link>
        <description>{{ site.description }}</description>
        <language>{{ collection.params.lang }}</language>
        <atom:link href="{{ uri.url(true) }}" rel="self" type="application/rss+xml"/>
        {% for post in collection %}
        {% if post.visible %}
        {% if date(post.date) > date("-7days") %}
        <item>
            <title>{{ post.title }}</title>
            <link>{{ post.url(true) }}</link>
            <description>
                <![CDATA[{{ post.content | truncate(140) }}]]>
            </description>
            <category>{{ post.taxonomy.tag|join(",") }}</category>
            <guid>{{ post.url(true) }}</guid>
            <pubDate>{{ post.date|date("D, d M Y H:i:s O") }}</pubDate>
        </item>                                      

        {% endif %}
    {% endif %}
{% endfor %}
    </channel>

</rss>
briankelleher commented 7 years ago

@rymdluo I appreciate it, I guess I will go with a custom solution.

flaviocopes commented 7 years ago

I am only able to replicate that error message by running on a page with

---
title: Blog
content:
---

# My blog

(no collection defined).

What is your page header content? And how are you calling the feed? On the collection page, right? Like, http://mysite.com/blog.rss, where Blog is a page that defines a collection.