From 2722512fd2a791a9925c587a9c65b8e1d627adf0 Mon Sep 17 00:00:00 2001 From: Tetrakern <26898880+Tetrakern@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:29:00 +0100 Subject: [PATCH] Add exclude parameters to showcase --- DOCUMENTATION.md | 4 +++- FILTERS.md | 4 ++++ includes/functions/_shortcodes.php | 32 +++++++++++++++++------------- partials/_showcase.php | 30 +++++++++++++++++++--------- 4 files changed, 46 insertions(+), 24 deletions(-) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index f08da1f2..78fb3dd0 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -669,7 +669,7 @@ Renders the search form with advanced options (if not disabled in the settings). ### Showcase -Renders dynamic grid of thumbnails with title, showing the latest eight posts of the specified type ordered by publishing date, descending. Requires **for** parameter. Optional parameters are **count**, **author**, **order**, **orderby**, **post_ids**, **no_cap**, and **class**. The thumbnail is either the **Landscape Image** or **Cover Image** (if available), with chapters defaulting to the parent story. +Renders dynamic grid of thumbnails with title, showing the latest eight posts of the specified type ordered by publishing date, descending. Requires **for** parameter. Optional parameters are **count**, **author**, **order**, **orderby**, **post_ids**, **exclude_cat_ids**, **exclude_tag_ids**, **no_cap**, and **class**. The thumbnail is either the **Landscape Image** or **Cover Image** (if available), with chapters defaulting to the parent story. * **for:** Desired post type, either `stories`, `chapters`, `collections`, or `recommendations`. * **count:** Limit posts to any positive number, although you should keep it reasonable. Default `8`. @@ -677,6 +677,8 @@ Renders dynamic grid of thumbnails with title, showing the latest eight posts of * **order:** Either `desc` (descending) or `asc` (ascending). Default `desc`. * **orderby:** The default is `date`, but you can also use `rand` and [more](https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters). * **post_ids:** Comma-separated list of post IDs, if you want to pick from a curated pool. +* **exclude_cat_ids:** Comma-separated list of category IDs to exclude. +* **exclude_tag_ids:** Comma-separated list of tag IDs to exclude. * **no_cap:** Set `true` if you want to hide the caption. * **class:** Additional CSS classes, separated by whitespace. diff --git a/FILTERS.md b/FILTERS.md index 0ace9b5e..7671f5ed 100644 --- a/FILTERS.md +++ b/FILTERS.md @@ -691,6 +691,8 @@ Filters the query arguments in the `fictioneer_showcase` shortcode. The optional * $post_status (string) – `'publish'` * $author_name (string|null) – `$args['author']` * $post__in (array) – `$args['post_ids']` +* $category__not_in (array|null) – `$args['excluded_cats']` +* $tag__not_in (array|null) – `$args['excluded_tags']` * $orderby (string) – `$args['orderby']` * $order (string) – `$args['order']` * $posts_per_page (int) – `$args['count']` @@ -704,6 +706,8 @@ Filters the query arguments in the `fictioneer_showcase` shortcode. The optional * $orderby (string) – Optional. Default `'date'`. * $order (string) – Optional. Default `'desc'`. * $post_ids (\[string]) – Array of post IDs. Default empty. +* $excluded_cats (\[string]) – Array of category IDs to exclude. Default empty. +* $excluded_tags (\[string]) – Array of tag IDs to exclude. Default empty. * $taxonomies (\[array]) – Array of taxonomy arrays (names). Default empty. * $relation (string) – Relationship between taxonomies. Default `'AND'`. * $no_cap (boolean) – Whether to hide captions. Default `false`. diff --git a/includes/functions/_shortcodes.php b/includes/functions/_shortcodes.php index 0b9272ff..2686149b 100644 --- a/includes/functions/_shortcodes.php +++ b/includes/functions/_shortcodes.php @@ -204,20 +204,22 @@ function fictioneer_get_shortcode_tax_query( $args ) { * * @since 5.0 * - * @param string $attr['for'] What the showcase is for. Allowed are chapters, - * collections, recommendations, and stories. - * @param string|null $attr['count'] Optional. Maximum number of items. Default 9. - * @param string|null $attr['author'] Optional. Limit items to a specific author. - * @param string|null $attr['order'] Optional. Order direction. Default 'DESC'. - * @param string|null $attr['orderby'] Optional. Order argument. Default 'date'. - * @param string|null $attr['post_ids'] Optional. Limit items to specific post IDs. - * @param string|null $attr['categories'] Optional. Limit items to specific category names. - * @param string|null $attr['tags'] Optional. Limit items to specific tag names. - * @param string|null $attr['fandoms'] Optional. Limit items to specific fandom names. - * @param string|null $attr['genres'] Optional. Limit items to specific genre names. - * @param string|null $attr['characters'] Optional. Limit items to specific character names. - * @param string|null $attr['rel'] Optional. Relationship between taxonomies. Default 'AND'. - * @param string|null $attr['class'] Optional. Additional CSS classes, separated by whitespace. + * @param string $attr['for'] What the showcase is for. Allowed are chapters, + * collections, recommendations, and stories. + * @param string|null $attr['count'] Optional. Maximum number of items. Default 9. + * @param string|null $attr['author'] Optional. Limit items to a specific author. + * @param string|null $attr['order'] Optional. Order direction. Default 'DESC'. + * @param string|null $attr['orderby'] Optional. Order argument. Default 'date'. + * @param string|null $attr['post_ids'] Optional. Limit items to specific post IDs. + * @param string|null $attr['exclude_tag_ids'] Optional. Exclude posts with these tags. + * @param string|null $attr['exclude_cat_ids'] Optional. Exclude posts with these categories. + * @param string|null $attr['categories'] Optional. Limit items to specific category names. + * @param string|null $attr['tags'] Optional. Limit items to specific tag names. + * @param string|null $attr['fandoms'] Optional. Limit items to specific fandom names. + * @param string|null $attr['genres'] Optional. Limit items to specific genre names. + * @param string|null $attr['characters'] Optional. Limit items to specific character names. + * @param string|null $attr['rel'] Optional. Relationship between taxonomies. Default 'AND'. + * @param string|null $attr['class'] Optional. Additional CSS classes, separated by whitespace. * * @return string The rendered shortcode HTML. */ @@ -256,6 +258,8 @@ function fictioneer_shortcode_showcase( $attr ) { 'orderby' => $orderby, 'order' => $order, 'post_ids' => $post_ids, + 'excluded_tags' => fictioneer_explode_list( $attr['exclude_tag_ids'] ?? '' ), + 'excluded_cats' => fictioneer_explode_list( $attr['exclude_cat_ids'] ?? '' ), 'taxonomies' => fictioneer_get_shortcode_taxonomies( $attr ), 'relation' => $rel, 'no_cap' => $no_cap == 'true' || $no_cap == '1', diff --git a/partials/_showcase.php b/partials/_showcase.php index e8a61014..780496dd 100644 --- a/partials/_showcase.php +++ b/partials/_showcase.php @@ -11,15 +11,17 @@ * @subpackage Fictioneer * @since 4.0 * - * @internal $args['type'] Post type if the showcase. - * @internal $args['count'] Maximum number of items. Default 8. - * @internal $args['order'] Order direction. Default 'DESC'. - * @internal $args['orderby'] Order argument. Default 'date'. - * @internal $args['author'] Author provided by the shortcode. - * @internal $args['post_ids'] Array of post IDs. Default empty. - * @internal $args['taxonomies'] Array of taxonomy arrays. Default empty. - * @internal $args['relation'] Relationship between taxonomies. - * @internal $args['classes'] Additional classes. + * @internal $args['type'] Post type if the showcase. + * @internal $args['count'] Maximum number of items. Default 8. + * @internal $args['order'] Order direction. Default 'DESC'. + * @internal $args['orderby'] Order argument. Default 'date'. + * @internal $args['author'] Author provided by the shortcode. + * @internal $args['post_ids'] Array of post IDs. Default empty. + * @internal $args['excluded_cats'] Array of category IDs to exclude. Default empty. + * @internal $args['excluded_tags'] Array of tag IDs to exclude. Default empty. + * @internal $args['taxonomies'] Array of taxonomy arrays. Default empty. + * @internal $args['relation'] Relationship between taxonomies. + * @internal $args['classes'] Additional classes. */ ?> @@ -45,6 +47,16 @@ if ( ! empty( $args['taxonomies'] ) ) { $query_args['tax_query'] = fictioneer_get_shortcode_tax_query( $args ); } +// Excluded tags? +if ( ! empty( $args['excluded_tags'] ) ) { + $query_args['tag__not_in'] = $args['excluded_tags']; +} + +// Excluded categories? +if ( ! empty( $args['excluded_cats'] ) ) { + $query_args['category__not_in'] = $args['excluded_cats']; +} + // Apply filters $query_args = apply_filters( 'fictioneer_filter_shortcode_showcase_query_args', $query_args, $args );