Add custom template tag file, search remain local on homepage instead of site-search
authorLaury GvR <laury@gaslightmedia.com>
Wed, 15 May 2019 23:31:31 +0000 (19:31 -0400)
committerLaury GvR <laury@gaslightmedia.com>
Wed, 15 May 2019 23:31:31 +0000 (19:31 -0400)
functions.php
lib/template-tags.php [new file with mode: 0644]
parts/content-none.php
parts/content-search.php
sections/footer.php
sections/search.php

index 6aa2d54..aaaf006 100644 (file)
@@ -458,14 +458,14 @@ function SearchFilter($query) {
 }
 add_filter('pre_get_posts','SearchFilter');
 
-// Exclude pages from search queries
-function exclude_pages_search_when_logged_in($query) {
-    if ( $query->is_search )
-        $query->set( 'post__not_in', array( 22,24,26,28 ) );
+// // Exclude pages from search queries
+// function exclude_pages_search_when_logged_in($query) {
+//     if ( $query->is_search )
+//         $query->set( 'post__not_in', array( 22,24,26,28 ) );
 
-    return $query;
-}
-add_filter( 'pre_get_posts', 'exclude_pages_search_when_logged_in' );
+//     return $query;
+// }
+// add_filter( 'pre_get_posts', 'exclude_pages_search_when_logged_in' );
 
 /*
 function change_wp_search_size($query) {
@@ -484,10 +484,10 @@ function display_memberfindme_directory() {
     $_REQUEST['textSearch'] = $_REQUEST['s'];
     $_REQUEST['action'] = 'list';
     $_REQUEST['event_name'] = $_REQUEST['s'];
-    echo do_shortcode('[glm-members-list view="list" text-search="'.stripslashes($_REQUEST['s']).'"]');
+    echo do_shortcode('[glm-members-list view="list" show="-search-filters-opened" text-search="'.stripslashes($_REQUEST['s']).'"]');
     if( isset($_REQUEST['event_name']) && !empty($_REQUEST['event_name'])){
         echo do_shortcode('[glm-members-event-list limit="10"]');
-        echo '<a href="' . get_permalink( 31026 ) . '">View All Events</a>';
+        echo '<a href="' . get_permalink( 757 ) . '">View All Events</a>';
     }
     // $my_postid = 30722;//This is page id or post id
     // $content_post = get_post($my_postid);
@@ -495,4 +495,22 @@ function display_memberfindme_directory() {
     // $content = apply_filters('the_content', $content);
     // $content = str_replace(']]>', ']]&gt;', $content);
     // echo $content;
-}
\ No newline at end of file
+}
+
+
+/**
+ * Custom template tags for this theme.
+ */
+require get_template_directory() . '/lib/template-tags.php';
+
+/*
+    * Switch default core markup for search form, comment form, and comments
+    * to output valid HTML5.
+    */
+add_theme_support( 'html5', array(
+    'search-form',
+    'comment-form',
+    'comment-list',
+    'gallery',
+    'caption',
+) );
\ No newline at end of file
diff --git a/lib/template-tags.php b/lib/template-tags.php
new file mode 100644 (file)
index 0000000..12b755f
--- /dev/null
@@ -0,0 +1,123 @@
+<?php
+/**
+ * Custom template tags for this theme.
+ *
+ * Eventually, some of the functionality here could be replaced by core features.
+ *
+ * @package uptravel
+ */
+
+if ( ! function_exists( 'uptravel_posted_on' ) ) :
+/**
+ * Prints HTML with meta information for the current post-date/time and author.
+ */
+function uptravel_posted_on() {
+       $time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
+       if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
+               $time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%4$s</time>';
+       }
+
+       $time_string = sprintf( $time_string,
+               esc_attr( get_the_date( 'c' ) ),
+               esc_html( get_the_date() ),
+               esc_attr( get_the_modified_date( 'c' ) ),
+               esc_html( get_the_modified_date() )
+       );
+
+       $posted_on = sprintf(
+               esc_html_x( 'Posted on %s', 'post date', 'uptravel' ),
+               '<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
+       );
+
+        // Not showing "by <author>" anymore
+//     $byline = sprintf(
+//             esc_html_x( 'by %s', 'post author', 'uptravel' ),
+//             '<span class="author vcard"><a class="url fn n" href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author() ) . '</a></span>'
+//     );
+
+       echo '<span class="posted-on">' . $posted_on . '</span><span class="byline"> ' . $byline . '</span>'; // WPCS: XSS OK.
+
+}
+endif;
+
+
+if ( ! function_exists( 'uptravel_entry_footer' ) ) :
+/**
+ * Prints HTML with meta information for the categories, tags and comments.
+ */
+function uptravel_entry_footer() {
+       // Hide category and tag text for pages.
+       if ( 'post' === get_post_type() ) {
+               /* translators: used between list items, there is a space after the comma */
+               $categories_list = get_the_category_list( esc_html__( ', ', 'uptravel' ) );
+               if ( $categories_list && uptravel_categorized_blog() ) {
+                       printf( '<p class="cat-links">' . esc_html__( 'Posted in %1$s', 'uptravel' ) . '</p>', $categories_list ); // WPCS: XSS OK.
+               }
+
+               /* translators: used between list items, there is a space after the comma */
+               // $tags_list = get_the_tag_list( '', esc_html__( ', ', 'uptravel' ) );
+               // if ( $tags_list ) {
+               //      printf( '<p class="tags-links">' . esc_html__( 'Tagged %1$s', 'uptravel' ) . '</p>', $tags_list ); // WPCS: XSS OK.
+               // }
+       }
+/*
+       if ( ! is_single() && ! post_password_required() && ( comments_open() || get_comments_number() ) ) {
+               echo '<span class="comments-link">';
+               comments_popup_link( esc_html__( 'Leave a comment', 'uptravel' ), esc_html__( '1 Comment', 'uptravel' ), esc_html__( '% Comments', 'uptravel' ) );
+               echo '</span>';
+       }
+*/
+//     edit_post_link(
+//             sprintf(
+//                     /* translators: %s: Name of current post */
+//                     esc_html__( 'Edit %s', 'uptravel' ),
+//                     the_title( '<span class="screen-reader-text">"', '"</span>', false )
+//             ),
+//             '<span class="edit-link">',
+//             '</span>'
+//     );
+}
+endif;
+
+/**
+ * Returns true if a blog has more than 1 category.
+ *
+ * @return bool
+ */
+function uptravel_categorized_blog() {
+       if ( false === ( $all_the_cool_cats = get_transient( 'uptravel_categories' ) ) ) {
+               // Create an array of all the categories that are attached to posts.
+               $all_the_cool_cats = get_categories( array(
+                       'fields'     => 'ids',
+                       'hide_empty' => 1,
+                       // We only need to know if there is more than one category.
+                       'number'     => 2,
+               ) );
+
+               // Count the number of categories that are attached to the posts.
+               $all_the_cool_cats = count( $all_the_cool_cats );
+
+               set_transient( 'uptravel_categories', $all_the_cool_cats );
+       }
+
+       if ( $all_the_cool_cats > 1 ) {
+               // This blog has more than 1 category so uptravel_categorized_blog should return true.
+               return true;
+       } else {
+               // This blog has only 1 category so uptravel_categorized_blog should return false.
+               return false;
+       }
+}
+
+/**
+ * Flush out the transients used in uptravel_categorized_blog.
+ */
+function uptravel_category_transient_flusher() {
+       if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
+               return;
+       }
+       // Like, beat it. Dig?
+       delete_transient( 'uptravel_categories' );
+}
+add_action( 'edit_category', 'uptravel_category_transient_flusher' );
+add_action( 'save_post',     'uptravel_category_transient_flusher' );
index 78d2292..96ed5d5 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @link https://codex.wordpress.org/Template_Hierarchy
  *
- * @package wmta
+ * @package uptravel
  */
 
 ?>
 
 
                        <header class="page-header">
-                               <h1 class="page-title">Search Results: <?php printf( esc_html__( '%s', 'wmta' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
+                               <h1 class="page-title">Search Results: <?php printf( esc_html__( '%s', 'uptravel' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
                        </header><!-- .page-heade-->
 
                        <?php display_memberfindme_directory() ?>
 
                        <header class="page-header">
-                               <h1 class="page-title"><?php esc_html_e( 'Related search results: Nothing Found', 'wmta' ); ?></h1>
+                               <h1 class="page-title"><?php esc_html_e( 'Related search results: Nothing Found', 'uptravel' ); ?></h1>
                        </header><!-- .page-header -->
 
-                       <p><?php esc_html_e( 'Sorry, but nothing matched your search terms or no search terms were found. Please try again with some different keywords.', 'wmta' ); ?></p>
+                       <p><?php esc_html_e( 'Sorry, but nothing matched your search terms or no search terms were found. Please try again with some different keywords.', 'uptravel' ); ?></p>
                        <?php
 
 
 
 
                        <header class="page-header">
-                               <h1 class="page-title">Search Results for: <?php printf( esc_html__( '%s', 'wmta' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
+                               <h1 class="page-title">Search Results for: <?php printf( esc_html__( '%s', 'uptravel' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
                        </header><!-- .page-heade-->
 
                        <?php display_memberfindme_directory() ?>
 
                        <header class="page-header">
-                               <h1 class="page-title"><?php esc_html_e( 'Related search results: Nothing Found', 'wmta' ); ?></h1>
+                               <h1 class="page-title"><?php esc_html_e( 'Related search results: Nothing Found', 'uptravel' ); ?></h1>
                        </header><!-- .page-header -->
 
-                       <p><?php esc_html_e( 'Sorry, but nothing matched your keywords or no keywords were found. Please try again with some different keywords.', 'wmta' ); ?></p>
+                       <p><?php esc_html_e( 'Sorry, but nothing matched your keywords or no keywords were found. Please try again with some different keywords.', 'uptravel' ); ?></p>
                        <?php
 
 
index b06d7d7..4484cd7 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @link https://codex.wordpress.org/Template_Hierarchy
  *
- * @package wmta
+ * @package uptravel
  */
 
 ?>
@@ -22,7 +22,7 @@
                <?php endif; ?>
 
                <div class="entry-meta">
-                       <?php wmta_posted_on(); ?>
+                       <?php uptravel_posted_on(); ?>
                </div><!-- .entry-meta -->
        </header><!-- .entry-header -->
 
@@ -31,7 +31,7 @@
        </div><!-- .entry-summary -->
 
        <footer class="entry-footer">
-               <?php wmta_entry_footer(); ?>
+               <?php uptravel_entry_footer(); ?>
        </footer><!-- .entry-footer -->
 
        <hr>
index 5165e40..f9990ce 100644 (file)
@@ -158,11 +158,11 @@ $cities = $decode_array['cities'];
 
         myEl.addEventListener('click', function() {
             var search_url = '<?php echo esc_url( home_url());?>'
-                + '/site-search'
-                + '/?s=' + encodeURI(document.getElementById('tag').value) + '&glm_action=list'
-                + '&categorySearch=' + encodeURI(document.getElementById('lbl').value)
-                + '&cityUserSearch[]=' + encodeURI(document.getElementById('xlo').value)
-                + '&regionUserSearch[]=' + encodeURI(document.getElementById('xre').value);
+                //+ "/site-search"
+                + "/?s=" + encodeURI(document.getElementById('tag').value) + '&glm_action=list'
+                + "&categorySearch=" + encodeURI(document.getElementById('lbl').value)
+                + "&cityUserSearch[]=" + encodeURI(document.getElementById('xlo').value)
+                + "&regionUserSearch[]=" + encodeURI(document.getElementById('xre').value);
             window.location = search_url;
             //console.log(search_url);
         }, false);
index 580f464..8e89d9c 100644 (file)
@@ -4,10 +4,10 @@
     </div>
     <div class="row">
         <?php if (get_search_query() == "") { ?>
-        <!-- <br><h2 class="search-result-header small-12 columns">Please enter a query in the search box. </h2> -->
+        <br><h2 class="search-result-header small-12 columns">Please enter a query in the search box. </h2>
         <br><h6 class="search-result-header small-12 columns">get_search_query() returned empty. </h6>
         <?php } else { ?>
-        <!-- <br><h2 class="search-result-header small-12 columns">Search Results for "<?php //echo get_search_query(); ?>"</h2> -->
+        <br><h2 class="search-result-header small-12 columns">Search Results for "<?php echo get_search_query(); ?>"</h2>
         <?php } ?>
     </div>
 
 
                     <?php if ( have_posts() && strlen( trim(get_search_query()) ) != 0 ) : ?>
 
-                    <header class="page-header">
-                        <h1 class="page-title"><?php printf( esc_html__( 'Related News for: %s', 'uptravel' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
-                    </header><!-- .page-header -->
+                        <header class="page-header">
+                            <h1 class="page-title"><?php printf( esc_html__( 'Related News for: %s', 'uptravel' ), '<span>' . get_search_query() . '</span>' ); ?></h1>
+                        </header><!-- .page-header -->
 
 
-                    <?php
-                    /* Start the Loop */
-                    while ( have_posts() ) : the_post();
+                        <?php
+                        /* Start the Loop */
+                        while ( have_posts() ) : the_post();
 
-                        /**
-                         * Run the loop for the search to output the results.
-                         * If you want to overload this in a child theme then include a file
-                         * called content-search.php and that will be used instead.
-                         */
-                        get_template_part( 'parts/content-search' );
+                            /**
+                             * Run the loop for the search to output the results.
+                             * If you want to overload this in a child theme then include a file
+                             * called content-search.php and that will be used instead.
+                             */
+                            get_template_part( 'parts/content-search' );
 
-                    endwhile;
+                        endwhile;
 
-                    the_posts_navigation();
+                        the_posts_navigation();
 
-                else :
+                    else :
 
-                    get_template_part( 'parts/content-none' );
+                        get_template_part( 'parts/content-none' );
 
-                endif; ?>
+                    endif; ?>
 
                 </main><!-- #main -->
             </section><!-- #primary -->