Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Using Blog: Is there a way to exclude pages from a listing (but keep them published)?

Solved by Paul Hibbitts View solution

Started by Dan Mahoney 8 years ago · 3 replies · 926 views
8 years ago

Hey all,

I'm very new to grav, and I've discovered using the blog template that I can set published: true or false, so I can work on (and save) a page as I'm building it.

However, what I'd like is to have a page published, but hidden from the listing and the RSS feed so I can show it to people before it's in the RSS (which triggers syndication elsewhere) and view the final version for formatting and editing.

Is this easily possible?

👍 1
8 years ago Solution

Hi @gushi, I've done something like this to hide posts in a blog listing page in my Open Course Hub Bootstrap theme using a bit of custom Twig and a page frontmatter variable called hide_from_post_list. However, this does not address your RSS feed issue.

Here is a generalized example of the Twig:

TWIG
        {% for child in collection %}
          {% if child.header.hide_from_post_list != true %}
            {% include 'partials/blog_item.html.twig' with {'blog':page, 'page':child, 'truncate':true} %}
          {% endif %}
        {% endfor %}

If you download my Open Course Hub skeleton you can explore a working example https://getgrav.org/downloads/skeletons

Hope the above helps!

8 years ago

A custom header like Paul suggested is exactly what you need in situations like this. There's nothing in Grav to stop you just adding your own headers for your own purposes and using those as needed (e.g. filtering a list) in Twig.

You could simply edit the RSS template to achieve the same thing.

(BTW I'd simplify Paul's template as

TWIG
{% for child in collection if child.header.hide_from_post_list != true %}
  {% include 'partials/blog_item.html.twig' with {'blog':page, 'page':child, 'truncate':true} %}
{% endfor %}

Twig for loops have some cool extras! And I might add child.header.hide_from_post_list is defined and in front of the if to allow you to be lazier.)

Also, there are probably better ways to manage this whole review/release process. Have a look for plugins that let you allow only certain logged in users to see your content. That seems more robust than hoping search engines don't accidentally index your unreleased content. Sorry would suggest but short on time now.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 125 19 hours ago
General · by pamtbaau, 24 hours ago
1 89 23 hours ago
General · by Andy Miller, 1 day ago
0 73 1 day ago
General · by Marcel, 12 months ago
6 382 5 days ago
General · by Duc , 6 days ago
3 69 6 days ago