Filtered pages list

I’m trying to build a site that has multiple blogs as well as standard content pages. In the admin the standard “pages” list is quickly going to become difficult to navigate if it also includes every type of page & post - even with the filter control at the top of the list.

Does anyone have a mechanism where I could add a new item to the navigation on the left which would only show content of a specific type? That way I could have a left navigation showing “Pages”, “Blogs”, “News” etc.

Thanks all!

Are you using the updated version of the Admin Plugin?

1 Like

Thanks @gnat - yes - I’m using the latest admin plugin. The problem is that there’s going to be a couple of hundred blog posts under two different pages. Over time that’s going to get really unwieldy to navigate.

What I’d like to do is have a navigation item on the left that shows only the blog posts - effectively a link that pre-selects filters from those dropdowns at the top of the pages list. Does that make sense?

Yes, it totally makes sense.

However, the list is filtered using JS and the plugin does not have a way to reach a filtered list of pages directly. You could however create custom secured pages that show you a filtered list along with relevant edit links.

You can also try asking at the Admin plugin’s Github repo Github: Grav Admin

Thanks @gnat - will give that a go :slight_smile:

Hi @parkersweb!

Did you find a solution for this issue? I need to filter pages by e.g. author or other and need a hint where or how to extend the search with an hook.

I would be very happy to hear from you!

Hey Christiana :wave: - I didn’t I’m afraid. I spent some time investigating, but didn’t ultimately come up with a solution. We’re up to 864 content items now - so it’s definitely still an issue. Would be great to hear if you find an answer!

@christiana83, @parkersweb, A post on this topic has recently been opened on the repo of Admin.

@pamtbaau yes, it was me :slight_smile:

@parkersweb for my issues i wrote an own filter by extending an own written admin plugin. that filter is autonomous and independent of the existing grav filter.

I wrote an blueprint for my searchform. Than I overwrite the “admin/themes/grav/templates/pages.html.twig” in my own plugin by adding the filter boxes as an partial:

 {% include 'partials/filter_pages.html.twig' with { blueprints: admin.blueprints('admin/pages/filter_pages') } %}

content of my partial:

{% for field in blueprints.fields %}
    {% if field.type %}
        {% set value = ? data.value( : data.toArray %}
        <div class="block block-{{ field.type }}">
            {% include ["forms/fields/#{field.type}/#{field.type}.html.twig", 'forms/fields/text/text.html.twig'] %}
    {% endif %}
{% endfor %}

{{ nonce_field('admin-form', 'admin-nonce')|raw }}

// […]

By using javascript I add the selected values of the filters as parameters to the url. or i change the reselected or deleted values.

$("#filter_pages select").change(function(){
// [...]

In my modified “admin/themes/grav/templates/pages.html.twig” i filter the pages outpout via twig variables

{# if filter params set in url#}
   {% if uri.query() %}
       {# if filter params set in url #}
       {% set filter_last_modified_by = uri.query('last_modified_by') ? uri.query('last_modified_by') : '' %}
       {% set filter_assignee = uri.query('assignee') ? uri.query('assignee') : '' %}
       {% set filter_status = uri.query('status') ? uri.query('status') : '' %}

       {% if uri.query('last_modified_by') or uri.query('assignee') or uri.query('status') %}
           {% set filter_on = true %}

           {# show last modified by #}
           {% if filter_last_modified_by != '' and filter_last_modified_by != last_modified_by %}
               {% set filter_show_item = false %}
           {% endif %}

           {# show assignee #}
           {% if filter_assignee != '' and filter_assignee != assignee %}
               {% set filter_show_item = false %}
           {% endif %}

           {# show drafts #}
           {% if filter_status == "draft" and p.header.draft == NULL %}
               {% set filter_show_item = false %}
           {% endif %}

           {# show reviews #}
           {% if filter_status == "review" and transition != "review" %}
               {% set filter_show_item = false %}
           {% endif %}

           {# show original #}
           {% if filter_status == "original" %}
               {% if transition == "review" or p.header.draft != NULL or p.published %}
                   {% set filter_show_item = false %}
               {% endif %}
           {% endif %}
       {% endif %}
   {% endif %}

For the filtered list I use an own if part

 {# if filter is on #}
   {% if filter_on %}
        {% if filter_show_item %}
            <div class="row page-item__row">

       {% endif %}
       {% if p.children().count > 0 %}
           {{ self.loop(p, depth + 1, twig_vars) }}
       {% endif %}
   {# else if filter is not on #}

Ah - awesome - thanks so much for sharing @christiana83! Will take a look…