Adds Page only search option and customizer options to tweak all search options variables.

This commit is contained in:
mateuswetah 2020-08-14 12:02:05 -03:00
parent 4cdb20fc5c
commit 192f118a99
8 changed files with 144 additions and 29 deletions

View File

@ -13,6 +13,9 @@ function onTainacanSearchSubmit($event) {
case 'posts':
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?onlyposts=true&s=' + document['tainacan-search-form'].s.value : '');
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':
default:
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?s=' + document['tainacan-search-form'].s.value : '');

View File

@ -275,7 +275,7 @@ nav{
opacity: 1.0;
max-height: 400px;
max-height: 100vh;
width: 260px;
width: 280px;
right: -4px;
}
}
@ -293,7 +293,7 @@ nav{
> .dropdown-menu {
top: 0;
right: -4px;
width: 260px;
width: 280px;
height: auto;
padding: 0;
left: inherit;
@ -324,10 +324,9 @@ nav{
border-bottom: 1px solid #dee2e6;
border-left: 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;
display: flex;
flex-direction: column;
column-count: 2;
label {
white-space: nowrap;
display: flex;
@ -337,7 +336,7 @@ nav{
}
}
&.show {
animation: searchFormAppear 0.4s ease;
animation: searchFormAppear 0.35s ease;
}
}

View File

@ -192,14 +192,18 @@ add_action( 'admin_head', 'tainacan_customize_editor_css');
*/
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();
$existing_post_types = $query->get( 'post_type' );
if ( !is_array($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' );

View File

@ -127,6 +127,23 @@ function tainacan_customize_register( $wp_customize ) {
'section' => 'tainacan_header_search',
'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
$wp_customize->add_setting( 'tainacan_search_on_items', array(
@ -142,6 +159,22 @@ function tainacan_customize_register( $wp_customize ) {
'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
$wp_customize->add_setting( 'tainacan_search_on_collections', array(
'type' => 'theme_mod',
@ -156,6 +189,22 @@ function tainacan_customize_register( $wp_customize ) {
'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
$wp_customize->add_setting( 'tainacan_search_on_posts', array(
'type' => 'theme_mod',
@ -170,6 +219,52 @@ function tainacan_customize_register( $wp_customize ) {
'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
*/

View File

@ -70,8 +70,8 @@ if ( ! function_exists( 'tainacan_pagination' ) ) :
$count_max = ( $to_paged - 1 ) * $cur_posts; ?>
<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">
<?php //translators: Example - Viewing Items: 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 //translators: Example - Viewing results: 1 to 12 of 345 ?>
<?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 class="col-sm-5 pr-md-0 justify-content-md-end">
<?php the_posts_pagination(

View File

@ -17,18 +17,43 @@
name="archive"
checked="checked"
id="search-global">
<?php _e( 'Global search', 'tainacan-interface' ); ?>
<?php echo get_theme_mod('tainacan_search_global_label', __( 'Global', 'tainacan-interface' ) ); ?>
</label>
<?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 if ( get_theme_mod('tainacan_search_on_items', false) ) : ?>
<?php endif;
if ( get_theme_mod('tainacan_search_on_items', false) ) : ?>
<label for="search-on-items">
<input
type="radio"
value="tainacan-items"
name="archive"
id="search-on-items">
<?php _e( 'Archive items', 'tainacan-interface' ); ?>
<?php echo get_theme_mod('tainacan_search_on_items_label', __( 'Items', 'tainacan-interface' ) ); ?>
</label>
<?php endif;
if ( get_theme_mod('tainacan_search_on_collections', false) ) : ?>
@ -38,20 +63,9 @@
value="tainacan-collections"
name="archive"
id="search-on-collections">
<?php _e( 'Archive collections', 'tainacan-interface' ); ?>
<?php echo get_theme_mod('tainacan_search_on_collections_label', __( 'Collections', 'tainacan-interface' ) ); ?>
</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; ?>
</div>
<?php endif; ?>

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
<?php
if ( !$_GET['onlyposts'] && is_search() ) {
if ( !$_GET['onlyposts'] && !$_GET['onlypages'] && is_search() ) {
$post_type = get_post_type();
$post_type_object = get_post_type_object($post_type);
$post_type_label = $post_type_object->labels->singular_name;
@ -15,7 +15,7 @@
</div>
<?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">
<?php if ( !$_GET['onlyposts'] && is_search() ) : ?>
<?php if ( !$_GET['onlyposts'] && !$_GET['onlypages'] && is_search() ) : ?>
<div class="title-area">
<h3 class="mb-3">
<a href="<?php the_permalink(); ?>" class="font-weight-bold"><?php the_title(); ?></a>