Add single param to Latest Updates

In addition to the type, this works for all.
This commit is contained in:
Tetrakern 2024-07-25 00:31:41 +02:00
parent f36857780e
commit 541b78d2d0
5 changed files with 8 additions and 1 deletions

View File

@ -1080,6 +1080,7 @@ Renders a multi-column grid of small cards, showing the latest four updated stor
* **count:** Limit updates to any positive number, although you should keep it reasonable. Default `4`. * **count:** Limit updates to any positive number, although you should keep it reasonable. Default `4`.
* **type:** Either `default`, `simple`, `single`, or `compact`. The other variants are smaller with less data. * **type:** Either `default`, `simple`, `single`, or `compact`. The other variants are smaller with less data.
* **single:** Whether to show only one chapter item (included in type `single`). Default `false`.
* **author:** Only show updates of a specific author. Make sure to use the url-safe nice_name. * **author:** Only show updates of a specific author. Make sure to use the url-safe nice_name.
* **order:** Either `desc` (descending) or `asc` (ascending). Default `desc`. * **order:** Either `desc` (descending) or `asc` (ascending). Default `desc`.
* **post_ids:** Comma-separated list of post IDs, if you want to pick from a curated pool. * **post_ids:** Comma-separated list of post IDs, if you want to pick from a curated pool.

View File

@ -1235,6 +1235,7 @@ Filters the WP_Query arguments in the `fictioneer_latest_updates` shortcode. The
**$args:** **$args:**
* $type (string) Either `'default'`, `'simple'`, `'single'`, and `'compact'`. * $type (string) Either `'default'`, `'simple'`, `'single'`, and `'compact'`.
* $single (boolean) Whether to show only one chapter item. Default `false`.
* $count (int) Maximum number of posts. Default `-1`. * $count (int) Maximum number of posts. Default `-1`.
* $author (boolean|string) Limit posts to a specific author. Default `false`. * $author (boolean|string) Limit posts to a specific author. Default `false`.
* $order (string) Order argument. Default `'DESC'`. * $order (string) Order argument. Default `'DESC'`.

View File

@ -613,6 +613,7 @@ add_shortcode( 'fictioneer_story_cards', 'fictioneer_shortcode_latest_stories' )
* @param string|null $attr['count'] Optional. Maximum number of items. Default 4. * @param string|null $attr['count'] Optional. Maximum number of items. Default 4.
* @param string|null $attr['author'] Optional. Limit posts to a specific author. * @param string|null $attr['author'] Optional. Limit posts to a specific author.
* @param string|null $attr['type'] Optional. Choose between 'default', 'simple', 'single', and 'compact'. * @param string|null $attr['type'] Optional. Choose between 'default', 'simple', 'single', and 'compact'.
* @param string|null $attr['single'] Optional. Whether to show only one chapter item. Default false.
* @param string|null $attr['post_ids'] Optional. Limit posts to specific post IDs. * @param string|null $attr['post_ids'] Optional. Limit posts to specific post IDs.
* @param string|null $attr['ignore_protected'] Optional. Whether to ignore protected posts. Default false. * @param string|null $attr['ignore_protected'] Optional. Whether to ignore protected posts. Default false.
* @param string|null $attr['exclude_tag_ids'] Optional. Exclude posts with these tags. * @param string|null $attr['exclude_tag_ids'] Optional. Exclude posts with these tags.
@ -640,6 +641,7 @@ add_shortcode( 'fictioneer_story_cards', 'fictioneer_shortcode_latest_stories' )
function fictioneer_shortcode_latest_story_updates( $attr ) { function fictioneer_shortcode_latest_story_updates( $attr ) {
// Defaults // Defaults
$args = fictioneer_get_default_shortcode_args( $attr, 4 ); $args = fictioneer_get_default_shortcode_args( $attr, 4 );
$args['single'] = filter_var( $attr['single'] ?? 0, FILTER_VALIDATE_BOOLEAN );
// Type // Type
$type = sanitize_text_field( $attr['type'] ?? 'default' ); $type = sanitize_text_field( $attr['type'] ?? 'default' );

View File

@ -12,6 +12,7 @@
* @since 4.3.0 * @since 4.3.0
* *
* @internal $args['type'] Type argument passed from shortcode ('compact'). * @internal $args['type'] Type argument passed from shortcode ('compact').
* @internal $args['single'] Whether to show only one chapter item. Default false.
* @internal $args['count'] Number of posts provided by the shortcode. * @internal $args['count'] Number of posts provided by the shortcode.
* @internal $args['author'] Author provided by the shortcode. * @internal $args['author'] Author provided by the shortcode.
* @internal $args['order'] Order of posts. Default 'DESC'. * @internal $args['order'] Order of posts. Default 'DESC'.

View File

@ -13,6 +13,7 @@
* @since 4.3.0 * @since 4.3.0
* *
* @internal $args['type'] Type argument passed from shortcode. Default 'default'. * @internal $args['type'] Type argument passed from shortcode. Default 'default'.
* @internal $args['single'] Whether to show only one chapter item. Default false.
* @internal $args['count'] Number of posts provided by the shortcode. * @internal $args['count'] Number of posts provided by the shortcode.
* @internal $args['author'] Author provided by the shortcode. * @internal $args['author'] Author provided by the shortcode.
* @internal $args['order'] Order of posts. Default 'DESC'. * @internal $args['order'] Order of posts. Default 'DESC'.
@ -184,8 +185,9 @@ remove_filter( 'posts_where', 'fictioneer_exclude_protected_posts' );
} }
$chapter_list[] = $chapter_post; $chapter_list[] = $chapter_post;
$max = ( $args['single'] || $args['type'] === 'single' ) ? 0 : 1;
if ( count( $chapter_list ) > ( $args['type'] === 'single' ? 0 : 1 ) ) { if ( count( $chapter_list ) > $max ) {
break; // Max one or two break; // Max one or two
} }
} }