Fixes global search and adds options to the customizer.
This commit is contained in:
parent
a195beb6e5
commit
b224b3b0b4
|
@ -2,7 +2,7 @@ function onTainacanSearchSubmit($event) {
|
||||||
|
|
||||||
if (document['tainacan-search-form']) {
|
if (document['tainacan-search-form']) {
|
||||||
|
|
||||||
if (document['tainacan-search-form'].archive && defined ( 'TAINACAN_VERSION' )) {
|
if (document['tainacan-search-form'].archive && tainacan_plugin !== undefined) {
|
||||||
switch (document['tainacan-search-form'].archive.value) {
|
switch (document['tainacan-search-form'].archive.value) {
|
||||||
case 'tainacan-items':
|
case 'tainacan-items':
|
||||||
document['tainacan-search-form'].action = tainacan_plugin.theme_items_list_url + (document['tainacan-search-form'].s ? '?search=' + document['tainacan-search-form'].s.value : '');
|
document['tainacan-search-form'].action = tainacan_plugin.theme_items_list_url + (document['tainacan-search-form'].s ? '?search=' + document['tainacan-search-form'].s.value : '');
|
||||||
|
@ -10,6 +10,9 @@ function onTainacanSearchSubmit($event) {
|
||||||
case 'tainacan-collections':
|
case 'tainacan-collections':
|
||||||
document['tainacan-search-form'].action = tainacan_plugin.theme_collection_list_url + (document['tainacan-search-form'].s ? '?s=' + document['tainacan-search-form'].s.value : '');
|
document['tainacan-search-form'].action = tainacan_plugin.theme_collection_list_url + (document['tainacan-search-form'].s ? '?s=' + document['tainacan-search-form'].s.value : '');
|
||||||
break;
|
break;
|
||||||
|
case 'everywhere':
|
||||||
|
document['tainacan-search-form'].action = '/' + (document['tainacan-search-form'].s ? '?everywhere=true&s=' + document['tainacan-search-form'].s.value : '');
|
||||||
|
break;
|
||||||
case 'posts':
|
case 'posts':
|
||||||
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 : '');
|
||||||
|
|
|
@ -303,7 +303,7 @@ nav{
|
||||||
background: white;
|
background: white;
|
||||||
padding: 0rem;
|
padding: 0rem;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 2.75rem;
|
height: 2.5rem;
|
||||||
}
|
}
|
||||||
.form-control {
|
.form-control {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
|
|
|
@ -191,9 +191,14 @@ add_action( 'admin_head', 'tainacan_customize_editor_css');
|
||||||
* @param object $query The main WordPress query.
|
* @param object $query The main WordPress query.
|
||||||
*/
|
*/
|
||||||
function tainacan_include_items_in_search_results( $query ) {
|
function tainacan_include_items_in_search_results( $query ) {
|
||||||
if ( $query->is_main_query() && $query->is_search() && ! is_admin()) {
|
if ( $_GET['everywhere'] && $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();
|
||||||
$query->set( 'post_type', array_merge( ['post', 'tainacan-collection'], $collections_post_types ) );
|
$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 ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_action( 'pre_get_posts', 'tainacan_include_items_in_search_results' );
|
add_action( 'pre_get_posts', 'tainacan_include_items_in_search_results' );
|
||||||
|
|
|
@ -109,8 +109,8 @@ function tainacan_customize_register( $wp_customize ) {
|
||||||
/**
|
/**
|
||||||
* Header settings
|
* Header settings
|
||||||
*/
|
*/
|
||||||
$wp_customize->add_section('tainacan_header_settings', array(
|
$wp_customize->add_section('tainacan_header_search', array(
|
||||||
'title' => __( 'Header settings', 'tainacan-interface' ),
|
'title' => __( 'Header search', 'tainacan-interface' ),
|
||||||
'priority' => 61,
|
'priority' => 61,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -124,23 +124,51 @@ function tainacan_customize_register( $wp_customize ) {
|
||||||
$wp_customize->add_control( 'tainacan_hide_search_input', array(
|
$wp_customize->add_control( 'tainacan_hide_search_input', array(
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'settings' => 'tainacan_hide_search_input',
|
'settings' => 'tainacan_hide_search_input',
|
||||||
'section' => 'tainacan_header_settings',
|
'section' => 'tainacan_header_search',
|
||||||
'label' => __( 'Hide search icon and input', 'tainacan-interface' )
|
'label' => __( 'Hide search icon and input', 'tainacan-interface' )
|
||||||
) );
|
) );
|
||||||
|
|
||||||
// Includes tainacan itens on search results
|
// Option to search directly on repository items list
|
||||||
$wp_customize->add_setting( 'tainacan_search_include_items', array(
|
$wp_customize->add_setting( 'tainacan_search_on_items', array(
|
||||||
'type' => 'theme_mod',
|
'type' => 'theme_mod',
|
||||||
'default' => false,
|
'default' => false,
|
||||||
'capability' => 'edit_theme_options',
|
'capability' => 'edit_theme_options',
|
||||||
'sanitize_callback' => 'tainacan_callback_sanitize_checkbox',
|
'sanitize_callback' => 'tainacan_callback_sanitize_checkbox',
|
||||||
) );
|
) );
|
||||||
$wp_customize->add_control( 'tainacan_search_include_items', array(
|
$wp_customize->add_control( 'tainacan_search_on_items', array(
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'settings' => 'tainacan_search_include_items',
|
'settings' => 'tainacan_search_on_items',
|
||||||
'section' => 'tainacan_header_settings',
|
'section' => 'tainacan_header_search',
|
||||||
'label' => __( 'Include tainacan itens on the search results list', 'tainacan-interface' ),
|
'label' => __( 'Display option to search on tainacan items repository list', 'tainacan-interface' )
|
||||||
'description' => __( 'Toggle to include tainacan itens on the search results list. By default it only lists WordPress Posts and Pages. The items will be displayed with the same appearence of posts, with their title, thumbnail and description.', 'tainacan-interface' )
|
) );
|
||||||
|
|
||||||
|
// Option to search directly on collections list
|
||||||
|
$wp_customize->add_setting( 'tainacan_search_on_collections', array(
|
||||||
|
'type' => 'theme_mod',
|
||||||
|
'default' => false,
|
||||||
|
'capability' => 'edit_theme_options',
|
||||||
|
'sanitize_callback' => 'tainacan_callback_sanitize_checkbox',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'tainacan_search_on_collections', array(
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'settings' => 'tainacan_search_on_collections',
|
||||||
|
'section' => 'tainacan_header_search',
|
||||||
|
'label' => __( 'Display option to search on tainacan collections list', 'tainacan-interface' )
|
||||||
|
) );
|
||||||
|
|
||||||
|
// Option to search globally posts, iem and collections
|
||||||
|
$wp_customize->add_setting( 'tainacan_search_global', array(
|
||||||
|
'type' => 'theme_mod',
|
||||||
|
'default' => false,
|
||||||
|
'capability' => 'edit_theme_options',
|
||||||
|
'sanitize_callback' => 'tainacan_callback_sanitize_checkbox',
|
||||||
|
) );
|
||||||
|
$wp_customize->add_control( 'tainacan_search_global', array(
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'settings' => 'tainacan_search_global',
|
||||||
|
'section' => 'tainacan_header_search',
|
||||||
|
'label' => __( 'Display option to search globally on items, collections and posts', 'tainacan-interface' ),
|
||||||
|
'description'=> __( 'By searching via this mode, the list result will include posts, items and collecitions. You wil be able do distinguish them by a tag next to the title.', 'tainacan-interface' )
|
||||||
) );
|
) );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -58,7 +58,8 @@ if ( ! function_exists( 'tainacan_enqueues' ) ) {
|
||||||
wp_register_script( 'tainacan_tainacanJS', get_template_directory_uri() . '/assets/js/js.js', '', TAINACAN_INTERFACE_VERSION, true );
|
wp_register_script( 'tainacan_tainacanJS', get_template_directory_uri() . '/assets/js/js.js', '', TAINACAN_INTERFACE_VERSION, true );
|
||||||
wp_enqueue_script( 'tainacan_tainacanJS' );
|
wp_enqueue_script( 'tainacan_tainacanJS' );
|
||||||
|
|
||||||
wp_enqueue_script( 'tainacan_searchBarRedirect', get_template_directory_uri() . '/assets/js/search-bar-redirect.js', [] , TAINACAN_INTERFACE_VERSION, false );
|
wp_register_script( 'tainacan_searchBarRedirect', get_template_directory_uri() . '/assets/js/search-bar-redirect.js', '', TAINACAN_INTERFACE_VERSION, false );
|
||||||
|
wp_enqueue_script( 'tainacan_searchBarRedirect' );
|
||||||
wp_enqueue_script( 'tainacan_copyLink', get_template_directory_uri() . '/assets/js/copy-link.js', [] , TAINACAN_INTERFACE_VERSION, false );
|
wp_enqueue_script( 'tainacan_copyLink', get_template_directory_uri() . '/assets/js/copy-link.js', [] , TAINACAN_INTERFACE_VERSION, false );
|
||||||
wp_localize_script( 'tainacan_copyLink', 'tainacan_copyLinkVars', array(
|
wp_localize_script( 'tainacan_copyLink', 'tainacan_copyLinkVars', array(
|
||||||
'linkCopied' => __( 'Copied! Link sent to the transfer area.', 'tainacan-interface' )
|
'linkCopied' => __( 'Copied! Link sent to the transfer area.', 'tainacan-interface' )
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
</button>
|
</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<?php if ( defined ( 'TAINACAN_VERSION' ) ) : ?>
|
<?php if ( defined ( 'TAINACAN_VERSION' ) && (get_theme_mod('tainacan_search_on_items', false) || get_theme_mod('tainacan_search_on_collections', false) || get_theme_mod('tainacan_search_global', false) ) ) : ?>
|
||||||
<div class="search-controls">
|
<div class="search-controls">
|
||||||
|
|
||||||
<label for="search-on-posts">
|
<label for="search-on-posts">
|
||||||
|
@ -20,25 +20,39 @@
|
||||||
<?php _e( 'Site posts', 'tainacan-interface' ); ?>
|
<?php _e( 'Site posts', 'tainacan-interface' ); ?>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label for="search-on-items">
|
<?php if ( get_theme_mod('tainacan_search_on_items', false) ) : ?>
|
||||||
<input
|
<label for="search-on-items">
|
||||||
type="radio"
|
<input
|
||||||
value="tainacan-items"
|
type="radio"
|
||||||
name="archive"
|
value="tainacan-items"
|
||||||
formaction="/items"
|
name="archive"
|
||||||
id="search-on-items">
|
id="search-on-items">
|
||||||
<?php _e( 'Archive items', 'tainacan-interface' ); ?>
|
<?php _e( 'Archive items', 'tainacan-interface' ); ?>
|
||||||
</label>
|
</label>
|
||||||
|
<?php endif;
|
||||||
|
if ( get_theme_mod('tainacan_search_on_collections', false) ) : ?>
|
||||||
|
|
||||||
<label for="search-on-collections">
|
<label for="search-on-collections">
|
||||||
<input
|
<input
|
||||||
type="radio"
|
type="radio"
|
||||||
value="tainacan-collections"
|
value="tainacan-collections"
|
||||||
name="archive"
|
name="archive"
|
||||||
formaction="/collections"
|
id="search-on-collections">
|
||||||
id="search-on-collections">
|
<?php _e( 'Archive collections', 'tainacan-interface' ); ?>
|
||||||
<?php _e( 'Archive collections', 'tainacan-interface' ); ?>
|
</label>
|
||||||
</label>
|
|
||||||
|
<?php endif;
|
||||||
|
if ( get_theme_mod('tainacan_search_global', false) ) : ?>
|
||||||
|
|
||||||
|
<label for="search-everywhere">
|
||||||
|
<input
|
||||||
|
type="radio"
|
||||||
|
value="everywhere"
|
||||||
|
name="archive"
|
||||||
|
id="search-everywhere">
|
||||||
|
<?php _e( 'Everywhere', 'tainacan-interface' ); ?>
|
||||||
|
</label>
|
||||||
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</form>
|
</form>
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,10 +1,11 @@
|
||||||
<?php
|
<?php
|
||||||
$post_type = get_post_type();
|
if ( $_GET['everywhere'] ) {
|
||||||
$post_type_object = get_post_type_object($post_type);
|
$post_type = get_post_type();
|
||||||
$post_type_label = $post_type_object->labels->singular_name;
|
$post_type_object = get_post_type_object($post_type);
|
||||||
$post_type_archive_link = get_post_type_archive_link($post_type);
|
$post_type_label = $post_type_object->labels->singular_name;
|
||||||
|
$post_type_archive_link = get_post_type_archive_link($post_type);
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<div class="row blog-post mb-4">
|
<div class="row blog-post mb-4">
|
||||||
<?php if ( has_post_thumbnail() ) : ?>
|
<?php if ( has_post_thumbnail() ) : ?>
|
||||||
<div class="col-xs-12 col-md-4 blog-thumbnail align-self-center text-center mb-4 mb-md-0">
|
<div class="col-xs-12 col-md-4 blog-thumbnail align-self-center text-center mb-4 mb-md-0">
|
||||||
|
@ -14,13 +15,19 @@
|
||||||
</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">
|
||||||
<div class="title-area">
|
<?php if ( $_GET['everywhere'] ) : ?>
|
||||||
|
<div class="title-area">
|
||||||
|
<h3 class="mb-3">
|
||||||
|
<a href="<?php the_permalink(); ?>" class="font-weight-bold"><?php the_title(); ?></a>
|
||||||
|
</h3>
|
||||||
|
|
||||||
|
<h4><a href="<?php echo $post_type_archive_link ?>"><?php echo $post_type_label ?></a></h4>
|
||||||
|
</div>
|
||||||
|
<?php else: ?>
|
||||||
<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>
|
||||||
</h3>
|
</h3>
|
||||||
|
<?php endif; ?>
|
||||||
<h4><a href="<?php echo $post_type_archive_link ?>"><?php echo $post_type_label ?></a></h4>
|
|
||||||
</div>
|
|
||||||
<?php echo '<p class="text-black">' . wp_trim_words( get_the_excerpt(), 28, '...' ) . '</p>'; ?>
|
<?php echo '<p class="text-black">' . wp_trim_words( get_the_excerpt(), 28, '...' ) . '</p>'; ?>
|
||||||
<?php tainacan_meta_date_author(); ?>
|
<?php tainacan_meta_date_author(); ?>
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@
|
||||||
|
|
||||||
<div style="margin: 0 4.1666667%" class="pagination">
|
<div style="margin: 0 4.1666667%" class="pagination">
|
||||||
<a class="d-inline-flex align-items-center" href="<?php echo tainacan_get_source_item_list_url(); ?>">
|
<a class="d-inline-flex align-items-center" href="<?php echo tainacan_get_source_item_list_url(); ?>">
|
||||||
<i class="tainacan-icon tainacan-icon-viewtable tainacan-icon-1-25em"></i> <span><?php echo __('Back to items list', 'tainacan') ?></span>
|
<i class="tainacan-icon tainacan-icon-viewtable tainacan-icon-1-25em"></i> <span><?php echo __('Back to items list', 'tainacan-interface') ?></span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue