X Features Cars Demo Power Plants Demo State Parks Demo Site Showcase Docs Tutorials Add-ons Buy

Template Configuration

Overview

A template tells FacetWP which posts to filter upon, and is required for facets to appear.

FacetWP supports 2 template types:

Automatic (CSS-based)

Add some facets to your existing category / shop / search / archive pages, and FacetWP will automatically handle the rest in most cases ūüôā

Manual (shortcode)

This approach involves adding a new shortcode-based template (via Settings > FacetWP), then pasting the shortcode into a WP page.

Option 1: CSS method

On archive pages, FacetWP will attempt to automatically detect the listing and wrap a¬†“facetwp-template”¬†CSS class around the listing.

Learn how it works, and how to troubleshoot if necessary.

Option 2: Shortcode method

As of version 3.2.0, FacetWP now includes a visual layout builder.

Watch the Layout Builder screencast to get started.

Templates can be displayed using shortcodes (in the body field, or text widgets) or PHP (in template files). For a template named my_template, you can use the shortcode:

[facetwp template="my_template"]

Or the PHP code:

<?php echo facetwp_display( 'template', 'my_template' ); ?>

Advanced mode

The layout builder is enabled by default, and will handle the vast majority of use-cases.

However, if you need extra control, click Switch to advanced mode to enable raw inputs.

Query Arguments

The Query Arguments field (based on WP_Query) determines the initial bucket of posts to load, how many¬†per page, and in which order.¬†Below,¬†we’ll fetch published posts, and show 15 per page:

<?php
return array(
    'post_type' => 'post',
    'post_status' => 'publish',
    'posts_per_page' => 15,
);

Display Code

The Display Code field is used for generating the template output. The following example will output the linked title for each post item.

<?php while ( have_posts() ): the_post(); ?>
<p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
<?php endwhile; ?>

Alternatively, you could put your display code into a PHP template file:

<?php
include( get_stylesheet_directory() . '/loop-index.php' );
?>