Added extra text for filter toggle buttons, added some comments

This commit is contained in:
Robbert de Kuiper 2017-03-31 10:40:22 +02:00
parent 0fc0d4964d
commit 4169abe1bd
4 changed files with 60 additions and 16 deletions

View File

@ -78,7 +78,6 @@
}
function toggleFilters() {
console.log(container);
container.classList.toggle('is-expanded-filters');
}

View File

@ -77,6 +77,12 @@ class Ajax_Filter_Posts {
);
}
/**
* Create shortcode
*
* @param Array $atts Array of given attributes
* @return String HTML initial rendered by shortcode
*/
public function create_shortcode($atts) {
$attributes = shortcode_atts( array(
@ -92,9 +98,17 @@ class Ajax_Filter_Posts {
'posts_per_page' => $attributes['posts_per_page'],
]);
$plural_post_name = strtolower(get_post_type_object($query->query['post_type'])->labels->name);
return include(plugin_dir_path( __FILE__ ) . 'templates/base.php');
}
/**
* Get a list of filters and terms, based on the taxonomies set in the shortcode
*
* @param String $taxonomies Comma seperated list of taxonomies
* @return Array List of taxonomies with terms
*/
protected function get_filterlist($taxonomies) {
$filterlists = explode(',', $taxonomies);
$filterlists = array_map('trim', $filterlists);
@ -103,6 +117,12 @@ class Ajax_Filter_Posts {
return $filterlists;
}
/**
* Get a list of filters and terms
*
* @param string $taxonomies A single taxonomy
* @return Array Taxonomy name and list of terms associated with the taxonomy
*/
protected function get_termlist($taxonomies) {
$list = [];
@ -119,6 +139,11 @@ class Ajax_Filter_Posts {
return $list;
}
/**
* Send new posts query via AJax after filters are changed in the frontend
*
* @return String HTML string with parsed posts or an error message
*/
public function process_filter_change() {
check_ajax_referer( 'filter-posts-nonce', 'nonce' );
@ -135,7 +160,7 @@ class Ajax_Filter_Posts {
'tax_query' => $tax
];
$response = $this->get_filter_posts($args, $response);
$response = $this->get_filter_posts($args);
if ($response) {
wp_send_json_success($response);
@ -146,7 +171,7 @@ class Ajax_Filter_Posts {
}
/**
* Converts the queried page to a real page
* Converts the queried page number to a real page number
*
* @param Object $query WP Query
* @return Integer Current page
@ -166,6 +191,12 @@ class Ajax_Filter_Posts {
return $query->get( 'paged' ) >= $query->max_num_pages;
}
/**
* Get the query paramaters based on set filters
*
* @param array $taxonomies list of taxanomies with terms
* @return array taxonomies prepared for the WordPress Query
*/
protected function get_tax_query_vars($taxonomies) {
$tax_query = [];
@ -192,6 +223,13 @@ class Ajax_Filter_Posts {
return $tax_query;
}
/**
* Check of the given thers are valid terms
*
* @param array $terms List of terms set by the filters
* @param string $tax Taxomy associated with the terms
* @return array List of valid terms
*/
protected function get_valid_terms($terms, $tax) {
$valid_terms = [];
@ -203,14 +241,18 @@ class Ajax_Filter_Posts {
}
return $valid_terms;
}
/**
* Set up filtered query
* Set up a filters query and parse the template
*
* @param array $args Arguments for the WordPress Query
* @return string HTMl to be sent via Ajax
*/
public function get_filter_posts($args, $response) {
public function get_filter_posts($args) {
$query = new WP_Query($args);
$response = [];
ob_start();
include(plugin_dir_path( __FILE__ ) . 'templates/partials/loop.php'); ;
$response['content'] = ob_get_clean();

View File

@ -1,14 +1,17 @@
<section data-post-type="<?= $attributes['post_type']; ?>" data-quantity="<?= $attributes['posts_per_page']; ?>" class="js-container-async ajax-posts">
<button class="js-toggle-filters ajax-posts__toggle-filter">
<span class="ajax-posts__hide-filter-text"><?php _e('Show filters', $this->plugin_name); ?></span>
<span class="ajax-posts__show-filter-text"><?php _e('Show results', $this->plugin_name); ?></span>
<span class="ajax-posts__filter-recipes-text">+ <?= __('Filter', $this->plugin_name) . ' ' . $plural_post_name; ?></span>
<span class="ajax-posts__show-recipes-text">+ <?= __('Show', $this->plugin_name) . ' ' . $plural_post_name; ?></span>
<span class="ajax-posts__hide-filters-text">- <?php _e('Hide filters', $this->plugin_name); ?></span>
</button>
<aside class="ajax-posts__filters">
<?php include(plugin_dir_path( __FILE__ ) . 'partials/filters.php' ); ?>
</aside>
<div class="ajax-posts__posts">
<div class="ajax-posts__status"></div>
<?php include(plugin_dir_path( __FILE__ ) . 'partials/loop.php' ); ?>
<div class="ajax-posts__view">
<aside class="ajax-posts__filters">
<?php include(plugin_dir_path( __FILE__ ) . 'partials/filters.php' ); ?>
</aside>
<div class="ajax-posts__status"></div>
<div class="ajax-posts__posts">
<?php include(plugin_dir_path( __FILE__ ) . 'partials/loop.php' ); ?>
</div>
</div>
<div class="ajax-posts__spinner">
<span class="ajax-posts__screen-reader-only"><?php _e('Loading', $this->plugin_name); ?></span>

View File

@ -18,7 +18,7 @@
<div class="ajax-posts-message ajax-posts-message--empty">
<svg xmlns="http://www.w3.org/2000/svg" width="31.95mm" height="41.85mm" viewBox="0 0 90.57 118.62"><defs><style>.a{fill:transparent;}.b,.c,.d,.e,.f,.g{fill:none;stroke:#aaa;stroke-miterlimit:10;}.b,.c,.d,.e,.f{stroke-width:1.45px;}.c{stroke-dasharray:5.41 5.41;}.d{stroke-dasharray:5.86 5.86;}.e{stroke-dasharray:6.41 6.41;}.f{stroke-dasharray:5.75 5.75;}.g{stroke-width:1.48px;stroke-dasharray:5.91;}</style></defs><polygon class="a" points="87.74 117.89 0.73 117.89 0.73 0.73 64.26 0.73 87.74 25.74 87.74 117.89"/><polyline class="b" points="87.74 114.98 87.74 117.89 84.84 117.89"/><line class="c" x1="79.42" y1="117.89" x2="6.34" y2="117.89"/><polyline class="b" points="3.63 117.89 0.73 117.89 0.73 114.98"/><line class="d" x1="0.73" y1="109.12" x2="0.73" y2="6.56"/><polyline class="b" points="0.73 3.63 0.73 0.73 3.63 0.73"/><line class="e" x1="10.05" y1="0.73" x2="58.14" y2="0.73"/><polyline class="b" points="61.35 0.73 64.26 0.73 66.25 2.85"/><polyline class="f" points="70.18 7.03 87.74 25.74 87.74 112.11"/><polyline class="g" points="63.89 0.73 63.89 26.18 87.74 26.18"/>
</svg>
<h4><?php printf( __('Oh, we couldn\'t find any %s', $this->plugin_name), strtolower(get_post_type_object($query->query['post_type'])->labels->name)); ?></h4>
<h4><?php printf( __('Oh, we couldn\'t find any %s', $this->plugin_name), $plural_post_name); ?></h4>
<p><?php printf( __('Try different filters or <a %s> reset them all.</a>', $this->plugin_name), 'href="#" class="js-reset-filters"'); ?></p>
</div>
<?php endif; ?>