Created
July 19, 2020 13:16
-
-
Save jchristopher/ab4439f9f8481fbb055c79947b033040 to your computer and use it in GitHub Desktop.
Show categories with SearchWP Live Ajax Search Results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Search results are contained within a div.searchwp-live-search-results | |
* which you can style accordingly as you would any other element on your site | |
* | |
* Some base styles are output in wp_footer that do nothing but position the | |
* results container and apply a default transition, you can disable that by | |
* adding the following to your theme's functions.php: | |
* | |
* add_filter( 'searchwp_live_search_base_styles', '__return_false' ); | |
* | |
* There is a separate stylesheet that is also enqueued that applies the default | |
* results theme (the visual styles) but you can disable that too by adding | |
* the following to your theme's functions.php: | |
* | |
* wp_dequeue_style( 'searchwp-live-search' ); | |
* | |
* You can use ~/searchwp-live-search/assets/styles/style.css as a guide to customize | |
*/ | |
?> | |
<?php if ( have_posts() ) : ?> | |
<?php while ( have_posts() ) : the_post(); ?> | |
<?php $categories = get_the_category_list( ', ' ); ?> | |
<div class="searchwp-live-search-result" role="option" id="" aria-selected="false"> | |
<p> | |
<a href="<?php echo esc_url( get_permalink() ); ?>"> | |
<?php the_title(); ?> » | |
</a> | |
<?php if ( ! empty( $categories ) ) : ?> | |
<br><strong>Categories:</strong><br> | |
<?php echo wp_kses_post( $categories ); ?> | |
<?php endif; ?> | |
</p> | |
</div> | |
<?php endwhile; ?> | |
<?php else : ?> | |
<p class="searchwp-live-search-no-results" role="option"> | |
<em><?php esc_html_e( 'No results found.', 'swplas' ); ?></em> | |
</p> | |
<?php endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment