Adds Page only search option and customizer options to tweak all search options variables.
This commit is contained in:
parent
4cdb20fc5c
commit
192f118a99
|
@ -13,6 +13,9 @@ function onTainacanSearchSubmit($event) {
|
||||||
case 'posts':
|
case 'posts':
|
||||||
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?onlyposts=true&s=' + document['tainacan-search-form'].s.value : '');
|
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?onlyposts=true&s=' + document['tainacan-search-form'].s.value : '');
|
||||||
break;
|
break;
|
||||||
|
case 'pages':
|
||||||
|
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?onlypages=true&s=' + document['tainacan-search-form'].s.value : '');
|
||||||
|
break;
|
||||||
case 'global':
|
case 'global':
|
||||||
default:
|
default:
|
||||||
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?s=' + document['tainacan-search-form'].s.value : '');
|
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?s=' + document['tainacan-search-form'].s.value : '');
|
||||||
|
|
|
@ -275,7 +275,7 @@ nav{
|
||||||
opacity: 1.0;
|
opacity: 1.0;
|
||||||
max-height: 400px;
|
max-height: 400px;
|
||||||
max-height: 100vh;
|
max-height: 100vh;
|
||||||
width: 260px;
|
width: 280px;
|
||||||
right: -4px;
|
right: -4px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ nav{
|
||||||
> .dropdown-menu {
|
> .dropdown-menu {
|
||||||
top: 0;
|
top: 0;
|
||||||
right: -4px;
|
right: -4px;
|
||||||
width: 260px;
|
width: 280px;
|
||||||
height: auto;
|
height: auto;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
left: inherit;
|
left: inherit;
|
||||||
|
@ -324,10 +324,9 @@ nav{
|
||||||
border-bottom: 1px solid #dee2e6;
|
border-bottom: 1px solid #dee2e6;
|
||||||
border-left: 1px solid #dee2e6;
|
border-left: 1px solid #dee2e6;
|
||||||
border-right: 1px solid #dee2e6;
|
border-right: 1px solid #dee2e6;
|
||||||
padding: 0.75rem 0.875rem 0.125rem 0.875rem;
|
padding: 0.75rem 0.875rem 0.5rem 0.875rem;
|
||||||
font-size: 0.75rem;
|
font-size: 0.75rem;
|
||||||
display: flex;
|
column-count: 2;
|
||||||
flex-direction: column;
|
|
||||||
label {
|
label {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
@ -337,7 +336,7 @@ nav{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
&.show {
|
&.show {
|
||||||
animation: searchFormAppear 0.4s ease;
|
animation: searchFormAppear 0.35s ease;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,14 +192,18 @@ add_action( 'admin_head', 'tainacan_customize_editor_css');
|
||||||
*/
|
*/
|
||||||
function tainacan_include_items_in_search_results( $query ) {
|
function tainacan_include_items_in_search_results( $query ) {
|
||||||
|
|
||||||
if ( $query->get( 'post_type' ) !== 'tainacan-collection' && !$_GET['onlyposts'] && $query->is_main_query() && $query->is_search() && ! is_admin()) {
|
if ( $query->get( 'post_type' ) !== 'tainacan-collection' && !$_GET['onlyposts'] && !$_GET['onlypages'] && $query->is_main_query() && $query->is_search() && ! is_admin()) {
|
||||||
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
|
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
|
||||||
$existing_post_types = $query->get( 'post_type' );
|
$existing_post_types = $query->get( 'post_type' );
|
||||||
|
|
||||||
if ( !is_array($existing_post_types) )
|
if ( !is_array($existing_post_types) )
|
||||||
$existing_post_types = [ $existing_post_types ];
|
$existing_post_types = [ $existing_post_types ];
|
||||||
|
|
||||||
$query->set( 'post_type', array_merge( $existing_post_types, ['post', 'tainacan-collection'], $collections_post_types ) );
|
$query->set( 'post_type', array_merge( $existing_post_types, ['post', 'page', 'tainacan-collection'], $collections_post_types ) );
|
||||||
|
} else if ( $_GET['onlypages'] && $query->is_main_query() && $query->is_search() && ! is_admin() ) {
|
||||||
|
$query->set( 'post_type', 'page' );
|
||||||
|
} else if ( $_GET['onlyposts'] && $query->is_main_query() && $query->is_search() && ! is_admin() ) {
|
||||||
|
$query->set( 'post_type', 'posts' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_action( 'pre_get_posts', 'tainacan_include_items_in_search_results' );
|
add_action( 'pre_get_posts', 'tainacan_include_items_in_search_results' );
|
||||||
|
|
|
@ -128,6 +128,23 @@ function tainacan_customize_register( $wp_customize ) {
|
||||||
'label' => __( 'Hide search icon and input', 'tainacan-interface' )
|
'label' => __( 'Hide search icon and input', 'tainacan-interface' )
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds option to configure the Global search option label.
|
||||||
|
*/
|
||||||
|
$wp_customize->add_setting( 'tainacan_search_global_label', array(
|
||||||
|
'type' => 'theme_mod',
|
||||||
|
'capability' => 'edit_theme_options',
|
||||||
|
'default' => __( 'Global', 'tainacan-interface' ),
|
||||||
|
'sanitize_callback' => 'sanitize_text_field'
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'tainacan_search_global_label', array(
|
||||||
|
'type' => 'text',
|
||||||
|
'settings' => 'tainacan_search_global_label',
|
||||||
|
'section' => 'tainacan_header_search',
|
||||||
|
'label' => __( 'Label for "Global" search option', 'tainacan-interface' ),
|
||||||
|
'description' => __( 'The Global search is the default. Its option will only be visible if at least one of the bellow are selected.')
|
||||||
|
) );
|
||||||
|
|
||||||
// Option to search directly on repository items list
|
// Option to search directly on repository items list
|
||||||
$wp_customize->add_setting( 'tainacan_search_on_items', array(
|
$wp_customize->add_setting( 'tainacan_search_on_items', array(
|
||||||
'type' => 'theme_mod',
|
'type' => 'theme_mod',
|
||||||
|
@ -142,6 +159,22 @@ function tainacan_customize_register( $wp_customize ) {
|
||||||
'label' => __( 'Display option to search on tainacan items repository list', 'tainacan-interface' )
|
'label' => __( 'Display option to search on tainacan items repository list', 'tainacan-interface' )
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds option to configure the Items search option label.
|
||||||
|
*/
|
||||||
|
$wp_customize->add_setting( 'tainacan_search_on_items_label', array(
|
||||||
|
'type' => 'theme_mod',
|
||||||
|
'capability' => 'edit_theme_options',
|
||||||
|
'default' => __( 'Items', 'tainacan-interface' ),
|
||||||
|
'sanitize_callback' => 'sanitize_text_field'
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'tainacan_search_on_items_label', array(
|
||||||
|
'type' => 'text',
|
||||||
|
'settings' => 'tainacan_search_on_items_label',
|
||||||
|
'section' => 'tainacan_header_search',
|
||||||
|
'label' => __( 'Label for the "items" search option', 'tainacan-interface' )
|
||||||
|
) );
|
||||||
|
|
||||||
// Option to search directly on collections list
|
// Option to search directly on collections list
|
||||||
$wp_customize->add_setting( 'tainacan_search_on_collections', array(
|
$wp_customize->add_setting( 'tainacan_search_on_collections', array(
|
||||||
'type' => 'theme_mod',
|
'type' => 'theme_mod',
|
||||||
|
@ -156,6 +189,22 @@ function tainacan_customize_register( $wp_customize ) {
|
||||||
'label' => __( 'Display option to search on tainacan collections list', 'tainacan-interface' )
|
'label' => __( 'Display option to search on tainacan collections list', 'tainacan-interface' )
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds option to configure the Collections search option label.
|
||||||
|
*/
|
||||||
|
$wp_customize->add_setting( 'tainacan_search_on_collections_label', array(
|
||||||
|
'type' => 'theme_mod',
|
||||||
|
'capability' => 'edit_theme_options',
|
||||||
|
'default' => __( 'Collections', 'tainacan-interface' ),
|
||||||
|
'sanitize_callback' => 'sanitize_text_field'
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'tainacan_search_on_collections_label', array(
|
||||||
|
'type' => 'text',
|
||||||
|
'settings' => 'tainacan_search_on_collections_label',
|
||||||
|
'section' => 'tainacan_header_search',
|
||||||
|
'label' => __( 'Label for the "Collections" search option', 'tainacan-interface' )
|
||||||
|
) );
|
||||||
|
|
||||||
// Option to search on wordpress posts only
|
// Option to search on wordpress posts only
|
||||||
$wp_customize->add_setting( 'tainacan_search_on_posts', array(
|
$wp_customize->add_setting( 'tainacan_search_on_posts', array(
|
||||||
'type' => 'theme_mod',
|
'type' => 'theme_mod',
|
||||||
|
@ -170,6 +219,52 @@ function tainacan_customize_register( $wp_customize ) {
|
||||||
'label' => __( 'Display option to search only on WordPress posts', 'tainacan-interface' )
|
'label' => __( 'Display option to search only on WordPress posts', 'tainacan-interface' )
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds option to configure the Posts search option label.
|
||||||
|
*/
|
||||||
|
$wp_customize->add_setting( 'tainacan_search_on_posts_label', array(
|
||||||
|
'type' => 'theme_mod',
|
||||||
|
'capability' => 'edit_theme_options',
|
||||||
|
'default' => __( 'Posts', 'tainacan-interface' ),
|
||||||
|
'sanitize_callback' => 'sanitize_text_field'
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'tainacan_search_on_posts_label', array(
|
||||||
|
'type' => 'text',
|
||||||
|
'settings' => 'tainacan_search_on_posts_label',
|
||||||
|
'section' => 'tainacan_header_search',
|
||||||
|
'label' => __( 'Label for the "Posts" search option', 'tainacan-interface' )
|
||||||
|
) );
|
||||||
|
|
||||||
|
// Option to search on wordpress pages only
|
||||||
|
$wp_customize->add_setting( 'tainacan_search_on_pages', array(
|
||||||
|
'type' => 'theme_mod',
|
||||||
|
'default' => false,
|
||||||
|
'capability' => 'edit_theme_options',
|
||||||
|
'sanitize_callback' => 'tainacan_callback_sanitize_checkbox',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'tainacan_search_on_pages', array(
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'settings' => 'tainacan_search_on_pages',
|
||||||
|
'section' => 'tainacan_header_search',
|
||||||
|
'label' => __( 'Display option to search only on WordPress pages', 'tainacan-interface' )
|
||||||
|
) );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds option to configure the Pages search option label.
|
||||||
|
*/
|
||||||
|
$wp_customize->add_setting( 'tainacan_search_on_pages_label', array(
|
||||||
|
'type' => 'theme_mod',
|
||||||
|
'capability' => 'edit_theme_options',
|
||||||
|
'default' => __( 'Pages', 'tainacan-interface' ),
|
||||||
|
'sanitize_callback' => 'sanitize_text_field'
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'tainacan_search_on_pages_label', array(
|
||||||
|
'type' => 'text',
|
||||||
|
'settings' => 'tainacan_search_on_pages_label',
|
||||||
|
'section' => 'tainacan_header_search',
|
||||||
|
'label' => __( 'Label for the "Pages" search option', 'tainacan-interface' )
|
||||||
|
) );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Social Share Links
|
* Social Share Links
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -70,8 +70,8 @@ if ( ! function_exists( 'tainacan_pagination' ) ) :
|
||||||
$count_max = ( $to_paged - 1 ) * $cur_posts; ?>
|
$count_max = ( $to_paged - 1 ) * $cur_posts; ?>
|
||||||
<div class="d-flex margin-pagination justify-content-between border-top pt-2">
|
<div class="d-flex margin-pagination justify-content-between border-top pt-2">
|
||||||
<div class="col-sm-3 d-none d-lg-block pl-0 view-items">
|
<div class="col-sm-3 d-none d-lg-block pl-0 view-items">
|
||||||
<?php //translators: Example - Viewing Items: 1 to 12 of 345 ?>
|
<?php //translators: Example - Viewing results: 1 to 12 of 345 ?>
|
||||||
<?php printf( __('Viewing collections: %1$d to %2$d of %3$d', 'tainacan-interface'), $count_max + 1, $count_max + $wp_query->post_count, $wp_query->found_posts ); ?>
|
<?php printf( __('Viewing results: %1$d to %2$d of %3$d', 'tainacan-interface'), $count_max + 1, $count_max + $wp_query->post_count, $wp_query->found_posts ); ?>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-5 pr-md-0 justify-content-md-end">
|
<div class="col-sm-5 pr-md-0 justify-content-md-end">
|
||||||
<?php the_posts_pagination(
|
<?php the_posts_pagination(
|
||||||
|
|
|
@ -17,18 +17,43 @@
|
||||||
name="archive"
|
name="archive"
|
||||||
checked="checked"
|
checked="checked"
|
||||||
id="search-global">
|
id="search-global">
|
||||||
<?php _e( 'Global search', 'tainacan-interface' ); ?>
|
<?php echo get_theme_mod('tainacan_search_global_label', __( 'Global', 'tainacan-interface' ) ); ?>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<?php if ( get_theme_mod('tainacan_search_on_items', false) ) : ?>
|
<?php if ( get_theme_mod('tainacan_search_on_posts', false) ) : ?>
|
||||||
|
<label for="search-on-posts">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
value="posts"
|
||||||
|
name="archive"
|
||||||
|
id="search-on-posts">
|
||||||
|
<?php echo get_theme_mod('tainacan_search_on_posts_label', __( 'Posts', 'tainacan-interface' ) ); ?>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<?php endif;
|
||||||
|
if ( get_theme_mod('tainacan_search_on_pages', false) ) : ?>
|
||||||
|
|
||||||
|
<label for="search-on-pages">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
value="pages"
|
||||||
|
name="archive"
|
||||||
|
id="search-on-pages">
|
||||||
|
<?php echo get_theme_mod('tainacan_search_on_pages_label', __( 'Pages', 'tainacan-interface' ) ); ?>
|
||||||
|
</label>
|
||||||
|
|
||||||
|
<?php endif;
|
||||||
|
if ( get_theme_mod('tainacan_search_on_items', false) ) : ?>
|
||||||
|
|
||||||
<label for="search-on-items">
|
<label for="search-on-items">
|
||||||
<input
|
<input
|
||||||
type="radio"
|
type="radio"
|
||||||
value="tainacan-items"
|
value="tainacan-items"
|
||||||
name="archive"
|
name="archive"
|
||||||
id="search-on-items">
|
id="search-on-items">
|
||||||
<?php _e( 'Archive items', 'tainacan-interface' ); ?>
|
<?php echo get_theme_mod('tainacan_search_on_items_label', __( 'Items', 'tainacan-interface' ) ); ?>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<?php endif;
|
<?php endif;
|
||||||
if ( get_theme_mod('tainacan_search_on_collections', false) ) : ?>
|
if ( get_theme_mod('tainacan_search_on_collections', false) ) : ?>
|
||||||
|
|
||||||
|
@ -38,20 +63,9 @@
|
||||||
value="tainacan-collections"
|
value="tainacan-collections"
|
||||||
name="archive"
|
name="archive"
|
||||||
id="search-on-collections">
|
id="search-on-collections">
|
||||||
<?php _e( 'Archive collections', 'tainacan-interface' ); ?>
|
<?php echo get_theme_mod('tainacan_search_on_collections_label', __( 'Collections', 'tainacan-interface' ) ); ?>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<?php endif;
|
|
||||||
if ( get_theme_mod('tainacan_search_on_posts', false) ) : ?>
|
|
||||||
<label for="search-on-posts">
|
|
||||||
<input
|
|
||||||
type="radio"
|
|
||||||
value="posts"
|
|
||||||
name="archive"
|
|
||||||
id="search-on-posts">
|
|
||||||
<?php _e( 'Site posts', 'tainacan-interface' ); ?>
|
|
||||||
</label>
|
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,5 @@
|
||||||
<?php
|
<?php
|
||||||
if ( !$_GET['onlyposts'] && is_search() ) {
|
if ( !$_GET['onlyposts'] && !$_GET['onlypages'] && is_search() ) {
|
||||||
$post_type = get_post_type();
|
$post_type = get_post_type();
|
||||||
$post_type_object = get_post_type_object($post_type);
|
$post_type_object = get_post_type_object($post_type);
|
||||||
$post_type_label = $post_type_object->labels->singular_name;
|
$post_type_label = $post_type_object->labels->singular_name;
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<div class="col-xs-12 blog-content <?php if ( has_post_thumbnail() ) :?>col-md-8 blog-flex<?php else : ?>col-md-12<?php endif; ?> align-self-center">
|
<div class="col-xs-12 blog-content <?php if ( has_post_thumbnail() ) :?>col-md-8 blog-flex<?php else : ?>col-md-12<?php endif; ?> align-self-center">
|
||||||
<?php if ( !$_GET['onlyposts'] && is_search() ) : ?>
|
<?php if ( !$_GET['onlyposts'] && !$_GET['onlypages'] && is_search() ) : ?>
|
||||||
<div class="title-area">
|
<div class="title-area">
|
||||||
<h3 class="mb-3">
|
<h3 class="mb-3">
|
||||||
<a href="<?php the_permalink(); ?>" class="font-weight-bold"><?php the_title(); ?></a>
|
<a href="<?php the_permalink(); ?>" class="font-weight-bold"><?php the_title(); ?></a>
|
||||||
|
|
Loading…
Reference in New Issue