concept-image / wp-archive-base
Archive and filter UI for Concept Image Acorn themes: Alpine + Tailwind components (x-archive.*, x-filter.*) published into the theme by `archive:install`, fed by concept-image/wp-query filters, AJAX through concept-image/wp-ajax (a generated per-archive action backed by ArchiveResponse).
Package info
gitlab.com/concept-image-public/wp-archive-base
pkg:composer/concept-image/wp-archive-base
Requires
- php: >=8.4
- ext-dom: *
- concept-image/wp-ajax: ^0.2
- concept-image/wp-custom-post-types: ^4.2
- concept-image/wp-query: ^1.2
- roots/acorn: ^6.4
Requires (Dev)
- brain/monkey: ^2.6
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- orchestra/testbench: ^10.0|^11.0
- pestphp/pest: ^4.0|^5.0
- pestphp/pest-plugin-arch: ^4.0|^5.0
- php-stubs/acf-pro-stubs: ^6.5
- szepeviktor/phpstan-wordpress: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Archive and filter components for Acorn themes
Alpine.js + Tailwind Blade components for Concept Image themes (<x-archive.*>,
<x-filter.*>) published into the theme and owned by the project, fed by the filters of
concept-image/wp-query and sent in AJAX by concept-image/wp-ajax.
- UI only. The data comes from the wp-query filters the archive's
archiveQuery()declares (wp-custom-post-typesHasArchiveQuery); WordPress runs its one main query; templates read it withX::archive()throughArchiveData. No second query, no filter engine. - Native fields are the source of truth. Every filter renders real checkboxes, radios, inputs and
<select>s, checked by the server. Alpine only enhances the display (pills, dropdowns, keyboard). Without JavaScript the archive is a plain GET form. - Logic in the package, markup in the theme.
Support\FilterViewturns a filter name into typed options, selected values, field name and URLs ($filter->urls()); the published component classes are thin and their views pure markup: restyle freely without forking logic. - Form AJAX by default.
<x-archive.archive :action="FilterNews::class">wraps<x-ajax::listing>; the filters go to a per-archive#[Ajax]action generated in the theme (wp acorn archive:action News), backed byArchiveResponse, which answers thefiltersandresultsregions and the URL.mode="navigate"and:ajax="false"are opt-in. - Ownership.
wp acorn archive:installcopies the components (and the client modules they need) into the theme,wp acorn archive:cleandeletes the unused ones, like wp-core-ui.
Requirements
- PHP 8.4+ (with
ext-dom), WordPress on Bedrock, Roots Acorn 6.4+ concept-image/wp-query^1.2,concept-image/wp-ajax^0.2,concept-image/wp-custom-post-types^4.2- Tailwind 4 and Alpine.js in the theme (wp-starter-theme), the wp-ajax client (
wp acorn ajax:install)
Installation
composer require concept-image/wp-archive-base # in the theme directory
wp acorn archive:install # the default set of components and their client
wp acorn ajax:install # the wp-ajax client, if not there yet
Register the client in resources/scripts/main.ts, before Alpine.start() (the command prints it):
import archive from './archive';
Alpine.plugin(archive);
The archive pattern
// app/CustomPostTypes/News.php: the archive's main query declares the filters
public static function archiveQuery(Builder $query): Builder
{
return $query->filters([
TaxonomyFilter::make(NewsCat::class)->archive()->withCounts(),
MetaFilter::make('level')->options(['junior' => 'Junior', 'senior' => 'Senior'])->multiple(),
Search::make('q'),
]);
}
wp acorn archive:action News # app/Actions/Archives/FilterNews.php + archives/news/{filters,results} views
// app/View/Composers/NewsArchive.php
protected static $views = ['archive-news', 'taxonomy-news-cat'];
public function with(): array
{
return ArchiveData::for(News::class)->toArray(); // items, total, title, formUrl, resetUrl, scope, isFiltered
}
{{-- resources/views/archive-news.blade.php --}}
<x-core.section>
<x-core.heading :level="1">{{ $title }}</x-core.heading>
<x-archive.archive :action="App\Actions\Archives\FilterNews::class">
<x-archives.news.filters :items="$items" :total="$total" />
<x-archives.news.results :items="$items" />
</x-archive.archive>
</x-core.section>
{{-- resources/views/components/archives/news/filters.blade.php (generated, then edited) --}}
@props(['items' => null, 'total' => null])
<x-archive.filters>
<x-filter.links name="news-cat" :label="__('Catégories', 'ci-replace')" />
<x-filter.checkboxes name="level" :label="__('Niveau', 'ci-replace')" variant="chips" />
<x-filter.search name="q" :label="__('Rechercher', 'ci-replace')" />
<x-filter.active />
</x-archive.filters>
The template and the action render the same region views with the same data, so the first load and every AJAX
update agree. Term links stay real links (/news-cat/tech/?level[]=junior works on first load, in AJAX, with
back/forward and on reload). See docs/archive-pattern.md.
Components
| Tag | Renders | Main props |
|---|---|---|
<x-archive.archive> | The archive's GET form: <x-ajax::listing> (form mode), <x-ajax::navigate> (mode="navigate") or plain (:ajax="false") | action, mode, ajax, url, scope, target, id, live, history |
<x-archive.filters> | The filters region (role="search"), <noscript> submit | region, label, submit |
<x-archive.results> | The results region: count, grid, empty state, pagination | items, cols (1–4), empty, count, pagination, append, tag |
<x-archive.count> | "12 résultats" (role="status") | items or total |
<x-archive.pagination> | wp-query's getPagination() in a data-ajax-links wrapper | items, url |
<x-archive.load-more> | The more region: "6 sur 40" and a link appending the next page (data-ajax-more) | items, region, target, label |
<x-filter.field> | Label, description, error around a control | label, description, error, id, group, hideLabel, size |
<x-filter.pillbox> | Multi-select dropdown, pills in the trigger, icons and descriptions, search, clear, counts | name, label, searchable, clearable, counts, hide-empty, icons, descriptions |
<x-filter.select> | Custom select (listbox, default: prefix, icons, descriptions, search, clear), native <select> (variant="native"), or the pillbox (multiple) | name, variant, multiple, prefix, placeholder, searchable, clearable, icons, descriptions, hide-empty, options |
<x-filter.checkboxes> | Checkbox group variant="list\|chips\|buttons\|cards", descriptions, icons, hierarchy, "Afficher plus" | name, variant, limit, counts, hide-empty, icons, descriptions |
<x-filter.radios> | Radios variant="list\|segmented\|cards" with an "all" choice, descriptions, icons | name, variant, all, full, options, hide-empty, icons, descriptions |
<x-filter.links> | Term archive links, aria-current, variant="pills\|tabs\|list" | name, variant, all, hide-empty |
<x-filter.toggle> | On/off switch (role="switch") | name, value |
<x-filter.search> | Search field, icon, clear button | name, placeholder, hideLabel |
<x-filter.sort> | Sort <select> | name, key, options, placeholder |
<x-filter.range> | Dual-thumb slider over {key}_min / {key}_max | name, unit |
<x-filter.date-range> | Two date fields {key}_from / {key}_to | name, min, max |
<x-filter.active> | Selected values as removable pills, "Tout effacer" | names, clear |
<x-filter.reset> | "Tout effacer" link, when filtered | url, filtered, label |
<x-filter.panel> | Sidebar from lg, drawer below with focus trap | label, total, active |
Every filter takes name (the wp-query filter: taxonomy, meta key, search key, range name), label, size
(sm, base) and, for options filters, key (the request key when the filter uses customKey()). Option
components take option descriptions / description-field (term description, ACF field or a value => text map) and
icons / icon-field (inline SVG sanitized by an allow-list, image URL, attachment), and hide-empty (options counted
0 by withCounts() hidden). Details: docs/components.md.
Commands
wp acorn archive:install [components...] [--all] [--force]: publish components (the default set: archive, filters, results, pagination, links, checkboxes, search, sort, active, and their dependencies), the client modules every installed component needs, and regenerateresources/scripts/archive/index.ts.wp acorn archive:clean [--dry-run] [--force]: delete the components no theme file uses and the client modules no kept component needs, regenerateindex.ts.wp acorn archive:list: every component, installed, used, in the default set, its client modules.wp acorn archive:action {PostType} [--force]: generate the archive's AJAX action and itsfilters/resultsregion views (stubs overridable in the theme'sstubs/wp-archive-base/).
Documentation
- Getting started
- The archive pattern
- Components
- AJAX modes
- Styling and customizing
- Commands and cleaning
- Upgrading from 3.x
Credits
- Banner icon: Library icons created by Magnific - Flaticon
License
MIT. See LICENSE.md.