> For the complete documentation index, see [llms.txt](https://docs.uichemy.com/llms.txt).
> Use it to discover all available pages before exploring further.

# Archive & Search Templates

Build custom archive layouts and a custom search results page using the Composer widget's loop system. Requires Pro.


Archive templates control the layout of category archives, tag archives, author archives, date archives, and custom taxonomy archives, any taxonomy your site registers gets its own Archive target automatically. A Search Results template controls what visitors see after they submit a search query. Both use Composer's loop system to render lists of matching posts.

<Callout kind="info">
Archive and Search templates require **UiChemy Pro**. See [Free vs Pro](/uichemy-composer/getting-started/free-vs-pro).
</Callout>

### Create an Archive Template

1. Go to **UiChemy → Theme Builder**.
2. Click **+ Add New → Archive** (or **Search Results** for search).
3. It opens in the WordPress editor (Gutenberg) by default, or in Elementor if it's installed and you choose it. Use **Edit** on the template card to reopen it later.
4. Add the **Composer** widget to the canvas.
5. Build your archive layout.
6. Click **Update** to save. Archive templates need a target; Search Results templates need nothing further, see below.

### The `term` Provider in Archive Templates

On taxonomy archive pages (category, tag, custom taxonomy), the `term` Twig provider resolves to the current archive term:

```html
<header class="archive-header uc-boxed">
  <span class="text-label">Category</span>
  <h1 class="text-heading-h1">{{ term.name }}</h1>
  {% if term.description %}
    <p class="archive-description">{{ term.description }}</p>
  {% endif %}
  <p class="text-body-sm">{{ term.count }} articles</p>
</header>
```

On author archive pages, use the `user` provider:

```html
<h1>Posts by {{ user.name }}</h1>
<img src="{{ user.avatar('80') }}" alt="{{ user.name }}">
```

### The Post Loop

Use `get_posts` with `paged: current_page()` to render the archive's posts:

```html
<section class="archive-grid uc-boxed">
  <div class="uc-grid-3">
    {% for post in get_posts({
      post_type: 'post',
      posts_per_page: 9,
      paged: current_page()
    }) %}
      <article class="uc-blog-card">
        <a href="{{ post.link }}">
          <img
            src="{{ post.thumbnail.src('medium') }}"
            alt="{{ post.thumbnail.alt }}"
          >
        </a>
        <div class="card-body">
          <span class="text-label">{{ post.categories.name }}</span>
          <h2 class="text-heading-h4">{{ post.title }}</h2>
          <p>{{ post.excerpt|truncate(100) }}</p>
          <a href="{{ post.link }}" class="text-label">Read More →</a>
        </div>
      </article>
    {% endfor %}
  </div>

  {{ loop_pagination()|raw }}
</section>
```

`current_page()` reads the current page number from the URL (`?loop_page=N`). `loop_pagination()` renders numbered page navigation links.

### Target and Conditions for Archives

An Archive template's primary scope is its **target**, chosen when you create it: blog (the main posts listing), author, date, a specific taxonomy (like Category or a custom taxonomy), or "any." Author and Date archives are targets, not conditions, there's no separate condition scope for them. Within a taxonomy target, conditions narrow further:

| Condition | What it covers |
|---|---|
| Post Category (any category) | All category archive pages |
| Post Category → specific term | One specific category's archive |
| Post Tag (any tag) | All tag archive pages |

To apply one template to all categories and another to a specific category, use two templates targeting Category: a broad one with **Include → Post Category (any)**, and a specific one with **Include → Post Category → "News"** (wins for the News category).

### Search Results Template

The search results template uses `request.get('s')` to access the search query, and `get_posts` with the `s` parameter to fetch matching results:

```html
<section class="search-results uc-boxed">
  <header class="search-header">
    <h1 class="text-heading-h2">
      {% if request.get('s') %}
        Results for "{{ request.get('s') }}"
      {% else %}
        Search
      {% endif %}
    </h1>
  </header>

  {% set results = get_posts({
    post_type: 'any',
    posts_per_page: 10,
    s: request.get('s'),
    paged: current_page()
  }) %}

  {% if results %}
    <div class="results-list">
      {% for post in results %}
        <article class="result-item">
          <h2 class="text-heading-h4">
            <a href="{{ post.link }}">{{ post.title }}</a>
          </h2>
          <p>{{ post.excerpt|truncate(150) }}</p>
          <span class="text-label">{{ post.date|date('F j, Y') }}</span>
        </article>
      {% endfor %}
    </div>
    {{ loop_pagination()|raw }}
  {% else %}
    <p class="no-results">No results found for "{{ request.get('s') }}".</p>
    <p>Try different keywords, or browse by <a href="/categories">category</a>.</p>
  {% endif %}
</section>
```

Search Results templates don't use conditions, there's nothing to set beyond building and activating the template. If you have more than one active Search Results template, the one you activated most recently is the one that shows.

### Tips

<ExpandableGroup>
  <Expandable title="Filtering by the current term in a loop" default-open="false">
    On a category archive, pass the current term to `get_posts` using `tax_query`, get the current term slug from `term.slug`:

    ```twig
    {% for post in get_posts({
      post_type: 'post',
      posts_per_page: 9,
      paged: current_page(),
      tax_query: [{
        taxonomy: 'category',
        field: 'slug',
        terms: [term.slug]
      }]
    }) %}
    ```
  </Expandable>

  <Expandable title="Empty archive state" default-open="false">
    Wrap your loop in `{% if %}...{% else %}...{% endif %}` to show a "no posts" message when the archive is empty.
  </Expandable>
</ExpandableGroup>

### Frequently Asked Questions

<ExpandableGroup>
  <Expandable title="Can I use Archive and Search Results templates on the free plan?" default-open="false">
    No. Both require **UiChemy Pro**. See [Free vs Pro](/uichemy-composer/getting-started/free-vs-pro).
  </Expandable>

  <Expandable title="How do I use a different layout for one category?" default-open="false">
    Create two Archive templates that target Category: a broad one for every category, and a specific one for the category you want. The more specific one wins on that category's pages.
  </Expandable>

  <Expandable title="Can I have more than one Search Results template?" default-open="false">
    You can, but only one shows. Search Results templates don't use conditions, so the one you activated most recently is the one visitors see.
  </Expandable>
</ExpandableGroup>

### Related

<Columns cols={2}>
  <Card title="Creating Templates" href="/uichemy-plugin/theme-builder/creating-templates">
    See the general template-creation flow this builds on.
  </Card>
  <Card title="Assigning Conditions" href="/uichemy-plugin/theme-builder/assigning-conditions">
    Narrow this archive down beyond its post type target.
  </Card>
  <Card title="Loops" href="/uichemy-composer/design-data/loops">
    Build the post grid this archive template lists.
  </Card>
  <Card title="Twig" href="/uichemy-composer/design-data/twig">
    Pull in each looped post's data dynamically.
  </Card>
  <Card title="Single Templates" href="/uichemy-plugin/theme-builder/single-templates">
    Build the matching single-post view this archive links to.
  </Card>
</Columns>
