Skip to content

Instantly share code, notes, and snippets.

@Ashkas
Last active April 20, 2018 18:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ashkas/77708db11d6f5fc2e3ab to your computer and use it in GitHub Desktop.
Save Ashkas/77708db11d6f5fc2e3ab to your computer and use it in GitHub Desktop.
FacetWP integration into Sage
<?php get_template_part('templates/head'); ?>
<body <?php body_class(); ?>>
<!--[if lt IE 9]>
<div class="alert alert-warning">
<?php _e('You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.', 'sage'); ?>
</div>
<![endif]-->
<?php
do_action('get_header');
get_template_part('templates/header');
?>
<div class="wrap container" role="document">
<div class="content">
<?php if(is_search()): ?>
<aside class="sidebar" role="complementary">
<!--
<?php if(is_dynamic_sidebar('sidebar-search')): ?>
<?php dynamic_sidebar('sidebar-search'); ?>
<?php endif; ?>
-->
<?php //echo do_shortcode('[facetwp facet="artist_number"]'); ?>
<?php echo facetwp_display( 'facet', 'artist_number' ); ?>
</aside><!-- /.sidebar -->
<?php endif; ?>
<main class="main" role="main" id="page">
<?php include Wrapper\template_path(); ?>
</main><!-- /.main -->
<div class="clearfix"></div>
</div><!-- /.content -->
</div><!-- /.wrap -->
<?php
do_action('get_footer');
get_template_part('templates/footer');
wp_footer();
?>
</body
function my_facetwp_is_main_query( $is_main_query, $query ) {
if ( isset( $query->query_vars['facetwp'] ) ) {
$is_main_query = true;
}
return $is_main_query;
}
add_filter( 'facetwp_is_main_query', 'my_facetwp_is_main_query', 10, 2 );
<?php // If it has posts
if (have_posts()) :
$counter = 0; ?>
<div class="row grid">
<div class="facetwp-template">
<?php while (have_posts()) : the_post();
get_template_part('templates/content-archive-grid', get_post_type() != 'post' ? get_post_type() : get_post_format());
$counter++;
if ($counter%2 == 0) echo '<div class="clearfix"></div>';
//if ($counter%4 == 0) echo '<div class="clearfix visible-md visible-lg"></div>';
endwhile; ?>
<div class="clearfix"></div>
</div>
</div>
<?php // Pagination
$page_args = array(
'prev_text' => '<span class="icon-arrow-left previous"></span>',
'next_text' => '<span class="icon-arrow-right"></span>',
);
$paginate_links = paginate_links($page_args);
if($paginate_links):
echo '<div class="pagination">';
echo $paginate_links;
echo '</div>';
endif;
endif; // have_posts ?>
global $wp_query; // get the global object
$thesearch = get_search_query(); // get the string searched
// merge them with one or several meta_queries to meet your demand
$args = array_merge( $wp_query->query, array(
's' => $thesearch,
'facetwp' => true
)
);
$query = new WP_Query( $args ); // alter the main query to include your custom parameters
if ($query->have_posts()) :
$counter = 0; ?>
<div class="row grid">
<div class="facetwp-template">
<?php while ($query->have_posts()) : $query->the_post();
get_template_part('templates/content-archive-grid', get_post_type() != 'post' ? get_post_type() : get_post_format());
$counter++;
if ($counter%2 == 0) echo '<div class="clearfix"></div>';
//if ($counter%4 == 0) echo '<div class="clearfix visible-md visible-lg"></div>';
endwhile; ?>
<div class="clearfix"></div>
</div>
</div>
<?php // Pagination
$page_args = array(
'prev_text' => '<span class="icon-arrow-left previous"></span>',
'next_text' => '<span class="icon-arrow-right"></span>',
);
$paginate_links = paginate_links($page_args);
if($paginate_links):
echo '<div class="pagination">';
echo $paginate_links;
echo '</div>';
endif;
endif; // have_posts ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment