A template tells FacetWP which posts to filter upon, and is required for facets to appear.
There are two types of templates to choose from:
Add some facets to your existing category / shop / search / archive pages, and FacetWP will automatically handle the rest in most cases 🙂
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
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:
Or the PHP code:
<?php echo facetwp_display( 'template', 'my_template' ); ?>
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.
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, );
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' ); ?>