Add sort-order-filter features

This commit is contained in:
Tetrakern 2023-06-08 22:44:43 +02:00
parent 2748733e7e
commit b6961c5f8c
14 changed files with 297 additions and 54 deletions

View File

@ -411,6 +411,10 @@ List page template hook. Fires right after the content section in the `chapters.
* $post_id (int) Current post ID.
* $chapters (WP_Query) Paginated query of all published chapters.
* $queried_type (string) `fcn_chapter`
* $query_args (array) The final query arguments used.
* $order (string) Current order query argument. Default 'desc'.
* $orderby (string) Current orderby query argument. Default 'modified'.
* $ago (int|string) Current value for the date query. Default 0.
**Hooked actions:**
* `fictioneer_sort_order_filter_interface( $args )` Interface to sort, order, and filter. Priority 20.
@ -481,6 +485,10 @@ List page template hook. Fires right after the content section in the `collectio
* $post_id (int) Current post ID.
* $collections (WP_Query) Paginated query of all published collections.
* $queried_type (string) `fcn_collection`
* $query_args (array) The final query arguments used.
* $order (string) Current order query argument. Default 'desc'.
* $orderby (string) Current orderby query argument. Default 'modified'.
* $ago (int|string) Current value for the date query. Default 0.
**Hooked actions:**
* `fictioneer_sort_order_filter_interface( $args )` Interface to sort, order, and filter. Priority 20.
@ -672,6 +680,10 @@ List page template hook. Fires right after the content section in the `recommend
* $post_id (int) Current post ID.
* $recommendations (WP_Query) Paginated query of all published recommendations.
* $queried_type (string) `fcn_recommendation`
* $query_args (array) The final query arguments used.
* $order (string) Current order query argument. Default 'desc'.
* $orderby (string) Current orderby query argument. Default 'modified'.
* $ago (int|string) Current value for the date query. Default 0.
**Hooked actions:**
* `fictioneer_sort_order_filter_interface( $args )` Interface to sort, order, and filter. Priority 20.
@ -758,6 +770,10 @@ List page template hook. Fires right after the content section in the `stories.p
* $post_id (int) Current post ID.
* $stories (WP_Query) Paginated query of all published stories.
* $queried_type (string) `fcn_story`
* $query_args (array) The final query arguments used.
* $order (string) Current order query argument. Default 'desc'.
* $orderby (string) Current orderby query argument. Default 'modified'.
* $ago (int|string) Current value for the date query. Default 0.
**Hooked actions:**
* `fictioneer_stories_statistics( $args )` Compiled statistics of all stories. Priority 10.

View File

@ -167,6 +167,9 @@ Filters the arguments passed to the `partials/_card-chapter` template part in th
**$card_args:**
* $cache (boolean) Return of `fictioneer_caching_active()`.
* $order (string) Current query order argument. Default 'desc'.
* $orderby (string) Current query orderby argument. Default 'modified'.
* $ago (int|string) Current date query argument part. Default 0.
**$args:**
* $current_page (int) Current page if paginated or `1`.
@ -196,7 +199,10 @@ Filters the arguments to query the chapters in the `chapters.php` template.
Filters the arguments passed to the `partials/_card-collection` template part in the `fictioneer_collections_list( $args )` function, normally added via the `fictioneer_collections_after_content` hook.
**$card_args:**
* $cache (boolean) Return of `fictioneer_caching_active()`
* $cache (boolean) Return of `fictioneer_caching_active()`.
* $order (string) Current query order argument. Default 'desc'.
* $orderby (string) Current query orderby argument. Default 'modified'.
* $ago (int|string) Current date query argument part. Default 0.
**$args:**
* $current_page (int) Current page if paginated or `1`.
@ -449,7 +455,10 @@ Filters the intermediate output array of the `fictioneer_get_post_meta_items()`
Filters the arguments passed to the `partials/_card-recommendation` template part in the `fictioneer_recommendations_list( $args )` function, normally added via the `fictioneer_recommendations_after_content` hook.
**$card_args:**
* $cache (boolean) Return of `fictioneer_caching_active()`
* $cache (boolean) Return of `fictioneer_caching_active()`.
* $order (string) Current query order argument. Default 'desc'.
* $orderby (string) Current query orderby argument. Default 'modified'.
* $ago (int|string) Current date query argument part. Default 0.
**$args:**
* $current_page (int) Current page if paginated or `1`.
@ -752,7 +761,10 @@ Filters the query arguments in the `fictioneer_showcase` shortcode. The optional
Filters the arguments passed to the `partials/_card-story` template part in the `fictioneer_stories_list( $args )` function, normally added via the `fictioneer_stories_after_content` hook.
**$card_args:**
* $cache (boolean) `fictioneer_caching_active()`
* $cache (boolean) Return of `fictioneer_caching_active()`.
* $order (string) Current query order argument. Default 'desc'.
* $orderby (string) Current query orderby argument. Default 'modified'.
* $ago (int|string) Current date query argument part. Default 0.
**$args:**
* $current_page (int) Current page if paginated or `1`.

View File

@ -23,6 +23,8 @@ $order = array_intersect( [strtolower( $_GET['order'] ?? 0 )], ['desc', 'asc'] )
$order = reset( $order ) ?: 'desc';
$orderby = array_intersect( [strtolower( $_GET['orderby'] ?? 0 )], ['modified', 'date', 'title', 'rand'] );
$orderby = reset( $orderby ) ?: 'modified';
$ago = $_GET['ago'] ?? 0;
$ago = is_numeric( $ago ) ? absint( $ago ) : sanitize_text_field( $ago );
// Prepare query
$query_args = array (
@ -36,6 +38,34 @@ $query_args = array (
'meta_value' => '0'
);
// Date query?
if ( is_numeric( $ago ) && $ago > 0 ) {
$query_args['date_query'] = array(
array(
'after'=> "{$ago} days ago",
'inclusive' => true,
)
);
} elseif ( ! empty( $ago ) ) {
$ago = array_intersect( [strtolower( $ago )], ['week', 'month', 'year'] );
$ago = reset( $ago ) ?: 0;
if ( ! empty( $ago ) ) {
$query_args['date_query'] = array(
'relation' => 'OR',
array(
'after'=> "1 {$ago} ago",
'inclusive' => true,
),
array(
'column' => 'post_modified',
'after'=> "1 {$ago} ago",
'inclusive' => true,
)
);
}
}
// Filter query arguments
$query_args = apply_filters( 'fictioneer_filter_chapters_query_args', $query_args, get_the_ID() );
@ -69,7 +99,8 @@ $list_of_chapters = new WP_Query( $query_args );
'queried_type' => 'fcn_chapter',
'query_args' => $query_args,
'order' => $order,
'orderby' => $orderby
'orderby' => $orderby,
'ago' => $ago
);
?>

View File

@ -23,6 +23,8 @@ $order = array_intersect( [strtolower( $_GET['order'] ?? 0 )], ['desc', 'asc'] )
$order = reset( $order ) ?: 'desc';
$orderby = array_intersect( [strtolower( $_GET['orderby'] ?? 0 )], ['modified', 'date', 'title', 'rand'] );
$orderby = reset( $orderby ) ?: 'modified';
$ago = $_GET['ago'] ?? 0;
$ago = is_numeric( $ago ) ? absint( $ago ) : sanitize_text_field( $ago );
// Prepare query
$query_args = array (
@ -34,6 +36,34 @@ $query_args = array (
'posts_per_page' => get_option( 'posts_per_page' ) ?? 8
);
// Date query?
if ( is_numeric( $ago ) && $ago > 0 ) {
$query_args['date_query'] = array(
array(
'after'=> "{$ago} days ago",
'inclusive' => true,
)
);
} elseif ( ! empty( $ago ) ) {
$ago = array_intersect( [strtolower( $ago )], ['week', 'month', 'year'] );
$ago = reset( $ago ) ?: 0;
if ( ! empty( $ago ) ) {
$query_args['date_query'] = array(
'relation' => 'OR',
array(
'after'=> "1 {$ago} ago",
'inclusive' => true,
),
array(
'column' => 'post_modified',
'after'=> "1 {$ago} ago",
'inclusive' => true,
)
);
}
}
// Filter query arguments
$query_args = apply_filters( 'fictioneer_filter_collections_query_args', $query_args, get_the_ID() );
@ -67,7 +97,8 @@ $list_of_collections = new WP_Query( $query_args );
'queried_type' => 'fcn_collection',
'query_args' => $query_args,
'order' => $order,
'orderby' => $orderby
'orderby' => $orderby,
'ago' => $ago
);
?>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -11,13 +11,14 @@ if ( ! function_exists( 'fictioneer_chapters_list' ) ) {
* @since 5.0
* @see chapters.php
*
* @param int $args['current_page'] Current page number of pagination or 1.
* @param int $args['post_id'] The post ID.
* @param WP_Query $args['chapters'] Paginated query of all published chapters.
* @param string $args['queried_type'] The queried post type ('fcn_chapter').
* @param array $args['query_args'] The query arguments used.
* @param string $args['order'] Current order. Default 'desc'.
* @param string $args['orderby'] Current orderby. Default 'modified'.
* @param int $args['current_page'] Current page number of pagination or 1.
* @param int $args['post_id'] The post ID.
* @param WP_Query $args['chapters'] Paginated query of all published chapters.
* @param string $args['queried_type'] The queried post type ('fcn_chapter').
* @param array $args['query_args'] The query arguments used.
* @param string $args['order'] Current order. Default 'desc'.
* @param string $args['orderby'] Current orderby. Default 'modified'.
* @param int|string $args['ago'] Current date query argument part. Default 0.
*/
function fictioneer_chapters_list( $args ) {
@ -32,7 +33,8 @@ if ( ! function_exists( 'fictioneer_chapters_list' ) ) {
$card_args = array(
'cache' => fictioneer_caching_active() && ! fictioneer_private_caching_active(),
'order' => $args['order'] ?? 'desc',
'orderby' => $args['orderby'] ?? 'modified'
'orderby' => $args['orderby'] ?? 'modified',
'ago' => $args['ago'] ?? 0
);
// Filter card arguments

View File

@ -11,13 +11,14 @@ if ( ! function_exists( 'fictioneer_collections_list' ) ) {
* @since 5.0
* @see collections.php
*
* @param int $args['current_page'] Current page number of pagination or 1.
* @param int $args['post_id'] The post ID.
* @param WP_Query $args['collections'] Paginated query of all published collections.
* @param string $args['queried_type'] The queried post type ('fcn_collection').
* @param array $args['query_args'] The query arguments used.
* @param string $args['order'] Current order. Default 'desc'.
* @param string $args['orderby'] Current orderby. Default 'modified'.
* @param int $args['current_page'] Current page number of pagination or 1.
* @param int $args['post_id'] The post ID.
* @param WP_Query $args['collections'] Paginated query of all published collections.
* @param string $args['queried_type'] The queried post type ('fcn_collection').
* @param array $args['query_args'] The query arguments used.
* @param string $args['order'] Current order. Default 'desc'.
* @param string $args['orderby'] Current orderby. Default 'modified'.
* @param int|string $args['ago'] Current date query argument part. Default 0.
*/
function fictioneer_collections_list( $args ) {
@ -32,7 +33,8 @@ if ( ! function_exists( 'fictioneer_collections_list' ) ) {
$card_args = array(
'cache' => fictioneer_caching_active() && ! fictioneer_private_caching_active(),
'order' => $args['order'] ?? 'desc',
'orderby' => $args['orderby'] ?? 'modified'
'orderby' => $args['orderby'] ?? 'modified',
'ago' => $args['ago'] ?? 0
);
// Filter card arguments

View File

@ -201,18 +201,45 @@ add_action( 'fictioneer_header', 'fictioneer_header_background', 10 );
* @param array $args {
* Array of arguments.
*
* @type int $current_page Current page if paginated or `1`.
* @type int $post_id Current post ID.
* @type string $queried_type Queried post type.
* @type array $query_args Query arguments used.
* @type string $order Current order or `desc`.
* @type string $orderby Current orderby or `'modified'`.
* @type int $current_page Current page if paginated or `1`.
* @type int $post_id Current post ID.
* @type string $queried_type Queried post type.
* @type array $query_args Query arguments used.
* @type string $order Current order or `desc`.
* @type string $orderby Current orderby or `'modified'`.
* @type int|string $ago Current date query argument part or `0`.
* }
*/
function fictioneer_sort_order_filter_interface( $args ) {
// Setup
$current_url = add_query_arg( array( 'order' => $args['order'] ), get_permalink() );
$current_url = get_permalink();
// Order?
if ( ! empty( $args['order'] ) ) {
$current_url = add_query_arg(
array( 'order' => $args['order'] ),
$current_url
);
}
// Orderby?
if ( ! empty( $args['orderby'] ) ) {
$current_url = add_query_arg(
array( 'orderby' => $args['orderby'] ),
$current_url
);
}
// Ago?
if ( ! empty( $args['ago'] ) ) {
$current_url = add_query_arg(
array( 'ago' => $args['ago'] ),
$current_url
);
}
// Order menu options
$orderby_menu = array(
'modified' => array(
'label' => __( 'Updated', 'fictioneer' ),
@ -227,9 +254,39 @@ function fictioneer_sort_order_filter_interface( $args ) {
'url' => add_query_arg( array( 'orderby' => 'title' ), $current_url ) . '#sof'
)
);
// Date menu options
$date_menu = array(
'0' => array(
'label' => __( 'Any Date', 'fictioneer' ),
'url' => remove_query_arg( 'ago', $current_url ) . '#sof'
),
'1' => array(
'label' => __( 'Last Day', 'fictioneer' ),
'url' => add_query_arg( array( 'ago' => 1 ), $current_url ) . '#sof'
),
'3' => array(
'label' => __( 'Last 3 Days', 'fictioneer' ),
'url' => add_query_arg( array( 'ago' => 3 ), $current_url ) . '#sof'
),
'week' => array(
'label' => __( 'Last Week', 'fictioneer' ),
'url' => add_query_arg( array( 'ago' => 'week' ), $current_url ) . '#sof'
),
'month' => array(
'label' => __( 'Last Month', 'fictioneer' ),
'url' => add_query_arg( array( 'ago' => 'month' ), $current_url ) . '#sof'
),
'year' => array(
'label' => __( 'Last Year', 'fictioneer' ),
'url' => add_query_arg( array( 'ago' => 'year' ), $current_url ) . '#sof'
)
);
// Order toggle link
$order_link = esc_url(
add_query_arg(
array( 'order' => $args['order'] === 'desc' ? 'asc' : 'desc', 'orderby' => $args['orderby'] ),
array( 'order' => $args['order'] === 'desc' ? 'asc' : 'desc' ),
$current_url
) . '#sof'
);
@ -239,9 +296,11 @@ function fictioneer_sort_order_filter_interface( $args ) {
// Start HTML ---> ?>
<div id="sof" class="sort-order-filter">
<div class="list-button _text popup-menu-toggle toggle-last-clicked" tabindex="0" role="button"><?php
echo $orderby_menu[ $args['orderby'] ]['label'] ?? __( 'Custom', 'fictioneer' );
echo '<div class="popup-menu _bottom _center">';
echo '<div class="popup-heading">' . __( 'Order By', 'fictioneer' ) . '</div>';
foreach( $orderby_menu as $tuple ) {
$url = esc_url( $tuple['url'] );
@ -250,10 +309,24 @@ function fictioneer_sort_order_filter_interface( $args ) {
echo '</div>';
?></div>
<div class="list-button _text popup-menu-toggle toggle-last-clicked" tabindex="0" role="button"><?php
echo $date_menu[ $args['ago'] ]['label'] ?? __( 'Custom', 'fictioneer' );
echo '<div class="popup-menu _bottom _center">';
echo '<div class="popup-heading">' . __( 'Time Range', 'fictioneer' ) . '</div>';
foreach( $date_menu as $tuple ) {
$url = esc_url( $tuple['url'] );
echo "<a href='{$url}'>{$tuple['label']}</a>";
}
echo '</div>';
?></div>
<a class="list-button _order <?php echo $args['order'] === 'desc' ? '_on' : '_off'; ?>" href="<?php echo $order_link; ?>">
<i class="fa-solid fa-arrow-up-short-wide _off"></i>
<i class="fa-solid fa-arrow-down-wide-short _on"></i>
<i class="fa-solid fa-arrow-up-short-wide _off"></i><i class="fa-solid fa-arrow-down-wide-short _on"></i>
</a>
</div>
<?php // <--- End HTML
}

View File

@ -11,13 +11,14 @@ if ( ! function_exists( 'fictioneer_recommendations_list' ) ) {
* @since 5.0
* @see recommendations.php
*
* @param int $args['current_page'] Current page number of pagination or 1.
* @param int $args['post_id'] The post ID.
* @param WP_Query $args['recommendations'] Paginated query of all published recommendations.
* @param string $args['queried_type'] The queried post type ('fcn_recommendation').
* @param array $args['query_args'] The query arguments used.
* @param string $args['order'] Current order. Default 'desc'.
* @param string $args['orderby'] Current orderby. Default 'modified'.
* @param int $args['current_page'] Current page number of pagination or 1.
* @param int $args['post_id'] The post ID.
* @param WP_Query $args['recommendations'] Paginated query of all published recommendations.
* @param string $args['queried_type'] The queried post type ('fcn_recommendation').
* @param array $args['query_args'] The query arguments used.
* @param string $args['order'] Current order. Default 'desc'.
* @param string $args['orderby'] Current orderby. Default 'modified'.
* @param int|string $args['ago'] Current date query argument part. Default 0.
*/
function fictioneer_recommendations_list( $args ) {
@ -32,7 +33,8 @@ if ( ! function_exists( 'fictioneer_recommendations_list' ) ) {
$card_args = array(
'cache' => fictioneer_caching_active() && ! fictioneer_private_caching_active(),
'order' => $args['order'] ?? 'desc',
'orderby' => $args['orderby'] ?? 'modified'
'orderby' => $args['orderby'] ?? 'modified',
'ago' => $args['ago'] ?? 0
);
// Filter card arguments

View File

@ -79,13 +79,14 @@ if ( ! function_exists( 'fictioneer_stories_list' ) ) {
* @since 5.0
* @see stories.php
*
* @param int $args['current_page'] Current page number of pagination or 1.
* @param int $args['post_id'] The post ID.
* @param WP_Query $args['stories'] Paginated query of all published stories.
* @param string $args['queried_type'] The queried post type ('fcn_story').
* @param array $args['query_args'] The query arguments used.
* @param string $args['order'] Current order. Default 'desc'.
* @param string $args['orderby'] Current orderby. Default 'modified'.
* @param int $args['current_page'] Current page number of pagination or 1.
* @param int $args['post_id'] The post ID.
* @param WP_Query $args['stories'] Paginated query of all published stories.
* @param string $args['queried_type'] The queried post type ('fcn_story').
* @param array $args['query_args'] The query arguments used.
* @param string $args['order'] Current order. Default 'desc'.
* @param string $args['orderby'] Current orderby. Default 'modified'.
* @param int|string $args['ago'] Current date query argument part. Default 0.
*/
function fictioneer_stories_list( $args ) {
@ -100,7 +101,8 @@ if ( ! function_exists( 'fictioneer_stories_list' ) ) {
$card_args = array(
'cache' => fictioneer_caching_active() && ! fictioneer_private_caching_active(),
'order' => $args['order'] ?? 'desc',
'orderby' => $args['orderby'] ?? 'modified'
'orderby' => $args['orderby'] ?? 'modified',
'ago' => $args['ago'] ?? 0
);
// Filter card arguments

View File

@ -23,6 +23,8 @@ $order = array_intersect( [strtolower( $_GET['order'] ?? 0 )], ['desc', 'asc'] )
$order = reset( $order ) ?: 'desc';
$orderby = array_intersect( [strtolower( $_GET['orderby'] ?? 0 )], ['modified', 'date', 'title', 'rand'] );
$orderby = reset( $orderby ) ?: 'modified';
$ago = $_GET['ago'] ?? 0;
$ago = is_numeric( $ago ) ? absint( $ago ) : sanitize_text_field( $ago );
// Prepare query
$query_args = array (
@ -34,6 +36,34 @@ $query_args = array (
'posts_per_page' => get_option( 'posts_per_page', 8 )
);
// Date query?
if ( is_numeric( $ago ) && $ago > 0 ) {
$query_args['date_query'] = array(
array(
'after'=> "{$ago} days ago",
'inclusive' => true,
)
);
} elseif ( ! empty( $ago ) ) {
$ago = array_intersect( [strtolower( $ago )], ['week', 'month', 'year'] );
$ago = reset( $ago ) ?: 0;
if ( ! empty( $ago ) ) {
$query_args['date_query'] = array(
'relation' => 'OR',
array(
'after'=> "1 {$ago} ago",
'inclusive' => true,
),
array(
'column' => 'post_modified',
'after'=> "1 {$ago} ago",
'inclusive' => true,
)
);
}
}
// Filter query arguments
$query_args = apply_filters( 'fictioneer_filter_recommendations_query_args', $query_args, get_the_ID() );
@ -67,7 +97,8 @@ $list_of_recommendations = new WP_Query( $query_args );
'queried_type' => 'fcn_recommendation',
'query_args' => $query_args,
'order' => $order,
'orderby' => $orderby
'orderby' => $orderby,
'ago' => $ago
);
?>

View File

@ -387,7 +387,7 @@ button[type=submit]:where(:not(._inline)) {
position: absolute;
z-index: 10;
background: var(--popup-menu-background);
color: var(--tooltip-text);
color: var(--popup-menu-text);
font-size: 14px;
line-height: 22px;
text-shadow: none;
@ -484,6 +484,16 @@ button[type=submit]:where(:not(._inline)) {
}
}
.popup-heading {
cursor: default;
position: relative;
font-family: var(--ff-note);
font-size: 12px;
line-height: 1.2;
padding: 4px 12px;
opacity: 0.5;
}
.no-results {
color: var(--fg-900);
padding: 0 2px;
@ -717,7 +727,7 @@ html:not(.logged-in) body:not(.logged-in) {
font-weight: 600;
line-height: 1.2;
letter-spacing: .02em;
padding: 4px 0;
padding: 4px 6px;
.popup-menu {
--vertical-offset: -4px;
@ -729,6 +739,6 @@ html:not(.logged-in) body:not(.logged-in) {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
gap: .5rem;
margin: 2rem 0 -0.5rem;
}

View File

@ -23,6 +23,8 @@ $order = array_intersect( [strtolower( $_GET['order'] ?? 0 )], ['desc', 'asc'] )
$order = reset( $order ) ?: 'desc';
$orderby = array_intersect( [strtolower( $_GET['orderby'] ?? 0 )], ['modified', 'date', 'title', 'rand'] );
$orderby = reset( $orderby ) ?: 'modified';
$ago = $_GET['ago'] ?? 0;
$ago = is_numeric( $ago ) ? absint( $ago ) : sanitize_text_field( $ago );
// Prepare query
$query_args = array (
@ -46,6 +48,34 @@ $query_args = array (
)
);
// Date query?
if ( is_numeric( $ago ) && $ago > 0 ) {
$query_args['date_query'] = array(
array(
'after'=> "{$ago} days ago",
'inclusive' => true,
)
);
} elseif ( ! empty( $ago ) ) {
$ago = array_intersect( [strtolower( $ago )], ['week', 'month', 'year'] );
$ago = reset( $ago ) ?: 0;
if ( ! empty( $ago ) ) {
$query_args['date_query'] = array(
'relation' => 'OR',
array(
'after'=> "1 {$ago} ago",
'inclusive' => true,
),
array(
'column' => 'post_modified',
'after'=> "1 {$ago} ago",
'inclusive' => true,
)
);
}
}
// Filter query arguments
$query_args = apply_filters( 'fictioneer_filter_stories_query_args', $query_args, get_the_ID() );
@ -79,7 +109,8 @@ $list_of_stories = new WP_Query( $query_args );
'queried_type' => 'fcn_story',
'query_args' => $query_args,
'order' => $order,
'orderby' => $orderby
'orderby' => $orderby,
'ago' => $ago
);
?>