Creates option to change default order of related items list.

This commit is contained in:
mateuswetah 2023-05-10 14:57:33 -03:00
parent b59ab93617
commit 0ac51d7b80
4 changed files with 52 additions and 9 deletions

View File

@ -4,7 +4,7 @@ $view_modes = tainacan_get_default_view_mode_choices();
$options = [ $options = [
$prefix . 'default_view_mode' => [ $prefix . 'default_view_mode' => [
'label' => __('Default view mode', 'blocksy'), 'label' => __('Default view mode', 'tainacan-blocksy'),
'type' => 'ct-select', 'type' => 'ct-select',
'value' => $view_modes['default_view_mode'], 'value' => $view_modes['default_view_mode'],
'view' => 'text', 'view' => 'text',

View File

@ -10,6 +10,8 @@ if (! isset($enabled)) {
$enabled = 'yes'; $enabled = 'yes';
} }
$order_options = tainacan_get_default_order_choices();
$options = [ $options = [
$prefix . 'display_items_related_to_this' => [ $prefix . 'display_items_related_to_this' => [
'label' => __( 'Display "Items related to this"', 'tainacan-blocksy' ), 'label' => __( 'Display "Items related to this"', 'tainacan-blocksy' ),
@ -51,7 +53,7 @@ $options = [
], ],
'options' => [ 'options' => [
$prefix . 'items_related_to_this_max_items_per_screen' => [ $prefix . 'items_related_to_this_max_items_per_screen' => [
'label' => __( 'Max amount of items per slide', 'blocksy' ), 'label' => __( 'Max amount of items per slide', 'tainacan-blocksy' ),
'type' => 'ct-number', 'type' => 'ct-number',
'design' => 'inline', 'design' => 'inline',
'value' => 6, 'value' => 6,
@ -68,7 +70,7 @@ $options = [
], ],
'options' => [ 'options' => [
$prefix . 'items_related_to_this_max_columns_count' => [ $prefix . 'items_related_to_this_max_columns_count' => [
'label' => __( 'Max amount of items columns', 'blocksy' ), 'label' => __( 'Max amount of items columns', 'tainacan-blocksy' ),
'type' => 'ct-number', 'type' => 'ct-number',
'design' => 'inline', 'design' => 'inline',
'value' => 4, 'value' => 4,
@ -77,6 +79,17 @@ $options = [
'sync' => '' 'sync' => ''
] ]
] ]
],
$prefix . 'items_related_to_this_order' => [
'label' => __('Order by', 'blocksy'),
'type' => 'ct-select',
'value' => 'title_asc',
'view' => 'text',
'design' => 'inline',
'sync' => '',
'choices' => blocksy_ordered_keys(
$order_options
)
] ]
] ]
] ]

View File

@ -133,10 +133,10 @@ if ( !function_exists('tainacan_get_default_view_mode_choices') ) {
} else { } else {
$default_view_mode = 'masonry'; $default_view_mode = 'masonry';
$enabled_view_modes = [ $enabled_view_modes = [
'masonry' => __('Masonry', 'tainacan-interface'), 'masonry' => __('Masonry', 'tainacan-blocksy'),
'cards' => __('Cards', 'tainacan-interface'), 'cards' => __('Cards', 'tainacan-blocksy'),
'table' => __('Table', 'tainacan-interface'), 'table' => __('Table', 'tainacan-blocksy'),
'grid' => __('Grid', 'tainacan-interface') 'grid' => __('Grid', 'tainacan-blocksy')
]; ];
} }
return [ return [
@ -147,4 +147,23 @@ if ( !function_exists('tainacan_get_default_view_mode_choices') ) {
} }
/**
* Retrieves possible orderby and order options to offer as default
*
* @return array An associative array with orderby and order options
*/
if ( !function_exists('tainacan_get_default_order_choices') ) {
function tainacan_get_default_order_choices() {
return [
'title_asc' => __( 'Title A-Z', 'tainacan-blocksy'),
'title_desc' => __( 'Title Z-A', 'tainacan-blocksy'),
'date_asc' => __( 'Latest created last', 'tainacan-blocksy'),
'date_desc' => __( 'Latest created first', 'tainacan-blocksy'),
'modified_asc' => __( 'Latest modified last', 'tainacan-blocksy'),
'modified_desc' => __( 'Latest modified first', 'tainacan-blocksy'),
];
}
}
?> ?>

View File

@ -5,6 +5,17 @@
$items_related_to_this_layout = get_theme_mod( $prefix . '_items_related_to_this_layout', 'carousel' ); $items_related_to_this_layout = get_theme_mod( $prefix . '_items_related_to_this_layout', 'carousel' );
$max_columns_count = get_theme_mod( $prefix . '_items_related_to_this_max_columns_count', 4 ); $max_columns_count = get_theme_mod( $prefix . '_items_related_to_this_max_columns_count', 4 );
$max_items_per_screen = get_theme_mod( $prefix . '_items_related_to_this_max_items_per_screen', 6 ); $max_items_per_screen = get_theme_mod( $prefix . '_items_related_to_this_max_items_per_screen', 6 );
$order_option = get_theme_mod( $prefix . '_items_related_to_this_order', 'title_asc' );
$order_option_split = explode( '_', $order_option );
$order_by = $order_option_split[0] ? $order_option_split[0] : 'title';
$order = $order_option_split[1] ? $order_option_split[1] : 'asc';
if ( !in_array($order_by, [ 'title', 'date', 'modified' ]) )
$order_by = 'title';
if ( !in_array($order, [ 'asc', 'desc' ]) )
$order = 'asc';
if ( function_exists('tainacan_the_related_items_carousel') && (get_theme_mod( $prefix . '_display_items_related_to_this', 'no' ) === 'yes') && tainacan_has_related_items() ) : ?> if ( function_exists('tainacan_the_related_items_carousel') && (get_theme_mod( $prefix . '_display_items_related_to_this', 'no' ) === 'yes') && tainacan_has_related_items() ) : ?>
@ -20,8 +31,8 @@
tainacan_the_related_items_carousel([ tainacan_the_related_items_carousel([
'items_list_layout' => $items_related_to_this_layout, 'items_list_layout' => $items_related_to_this_layout,
'collection_heading_tag' => 'h3', 'collection_heading_tag' => 'h3',
'order' => 'asc', 'order' => $order,
'orderby' => 'title', 'orderby' => $order_by,
'dynamic_items_args' => [ 'dynamic_items_args' => [
'max_columns_count' => $max_columns_count 'max_columns_count' => $max_columns_count
], ],