Advertisement
Guenni007

loop-search

Oct 4th, 2024 (edited)
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.68 KB | None | 0 0
  1. <?php
  2. if( ! defined( 'ABSPATH' ) ) {  exit;  }    // Exit if accessed directly
  3.  
  4. global $avia_config;
  5.  
  6.  
  7. // check if we got posts to display:
  8. if( have_posts() )
  9. {
  10.     $first = true;
  11.  
  12.     $counterclass = '';
  13.     $post_loop_count = 1;
  14.     $page = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  15.     if( $page > 1 )
  16.     {
  17.         $post_loop_count = ( (int)( $page - 1 ) * (int) get_query_var( 'posts_per_page' ) ) + 1;
  18.     }
  19.  
  20.     $blog_style = avia_get_option( 'blog_style', 'multi-big' );
  21.  
  22.     while( have_posts() )
  23.     {
  24.         the_post();
  25.  
  26.         $the_id = get_the_ID();
  27.         $parity = $post_loop_count % 2 ? 'odd' : 'even';
  28.         $last = count( $wp_query->posts ) == $post_loop_count ? ' post-entry-last ' : '';
  29.         $post_class = "post-entry-{$the_id} post-loop-{$post_loop_count} post-parity-{$parity} {$last} {$blog_style}";
  30.         $post_format = get_post_format() ? get_post_format() : 'standard';
  31.  
  32.         $aria_label = 'aria-label="' . __( 'Search Result:', 'avia_framework' ) . ' ' . esc_attr( get_the_title() ) . '"';
  33.  
  34.         /**
  35.          * @since 6.0.3
  36.          * @param string $aria_label
  37.          * @param string $context
  38.          * @param WP_Post|null $current_post
  39.          * @return string
  40.          */
  41.         $aria_label = apply_filters( 'avf_aria_label_for_header', $aria_label, __FILE__, get_post() );
  42.  
  43.     ?>
  44.         <article <?php post_class( "post-entry post-entry-type-{$post_format} {$post_class} " ); avia_markup_helper( array( 'context' => 'entry' ) ); ?>>
  45.             <div class="entry-content-wrapper clearfix <?php echo $post_format; ?>-content">
  46.                 <header class="entry-content-header" <?php echo $aria_label; ?> >
  47. <?php
  48.  
  49.  
  50. // here is the place to include an image to search results page
  51.                     echo "<span class='search-result-counter {$counterclass}'>{$post_loop_count}</span>";
  52.                     $searchimage = get_the_post_thumbnail( $the_id, 'medium' );
  53.                     echo "<span class='search-result-image'><a title='" . the_title_attribute( 'echo=0' ) . "' href='" . get_permalink() . "' {$markup}>{$searchimage}</a></span>";
  54.  
  55.  
  56.                     $default_heading = 'h2';
  57.                     $args = array(
  58.                                 'heading'       => $default_heading,
  59.                                 'extra_class'   => ''
  60.                             );
  61.  
  62.                     /**
  63.                      * @since 4.5.5
  64.                      * @return array
  65.                      */
  66.                     $args = apply_filters( 'avf_customize_heading_settings', $args, 'loop_search', array() );
  67.  
  68.                     $heading = ! empty( $args['heading'] ) ? $args['heading'] : $default_heading;
  69.                     $css = ! empty( $args['extra_class'] ) ? $args['extra_class'] : '';
  70.  
  71.                     //echo the post title
  72.                     $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false));
  73.  
  74.                     echo "<{$heading} class='post-title entry-title {$css}'><a title='" . the_title_attribute( 'echo=0' ) . "' href='" . get_permalink() . "' {$markup}>" . get_the_title() . "</a></{$heading}>";
  75.  
  76.                     echo '<span class="post-meta-infos">';
  77.  
  78.                         $meta_info = array();
  79.  
  80.                         /**
  81.                          * @since 4.8.8
  82.                          * @param string $hide_meta_only
  83.                          * @param string $context
  84.                          * @return string
  85.                          */
  86.                         $meta_separator = apply_filters( 'avf_post_metadata_seperator', '<span class="text-sep">/</span>', 'loop-search' );
  87.  
  88.                         if( 'blog-meta-date' == avia_get_option( 'blog-meta-date' ) )
  89.                         {
  90.                             $meta_time  = '<time class="date-container minor-meta updated" ' . avia_markup_helper( array( 'context' => 'entry_time', 'echo' => false ) ) . '>';
  91.                             $meta_time .=       get_the_time( get_option( 'date_format' ) );
  92.                             $meta_time .= '</time>';
  93.  
  94.                             $meta_info['date'] = $meta_time;
  95.                         }
  96.  
  97.                         if( get_post_type() !== 'page' && 'blog-meta-comments' == avia_get_option( 'blog-meta-comments' ) )
  98.                         {
  99.                             if( get_comments_number() != '0' || comments_open() )
  100.                             {
  101.                                 $meta_comment = '<span class="comment-container minor-meta">';
  102.  
  103.                                 ob_start();
  104.                                 comments_popup_link(
  105.                                                 "0 " . __( 'Comments', 'avia_framework' ),
  106.                                                 "1 " . __( 'Comment' , 'avia_framework' ),
  107.                                                 "% " . __( 'Comments', 'avia_framework' ),
  108.                                                 'comments-link',
  109.                                                 __( 'Comments Disabled', 'avia_framework' )
  110.                                             );
  111.  
  112.                                 $meta_comment .= ob_get_clean();
  113.                                 $meta_comment .= '</span>';
  114.  
  115.                                 $meta_info['comment'] = $meta_comment;
  116.                             }
  117.                         }
  118.  
  119.                         $taxonomies  = get_object_taxonomies(get_post_type($the_id));
  120.                         $cats = '';
  121.  
  122.                         $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array( 'post_tag', 'post_format' ) );
  123.  
  124.                         /**
  125.                          *
  126.                          * @since ????
  127.                          * @since 4.8.8                     added $context
  128.                          * @param array $excluded_taxonomies
  129.                          * @param string $post_type
  130.                          * @param int $the_id
  131.                          * @param string $context
  132.                          * @return array
  133.                          */
  134.                         $excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies', $excluded_taxonomies, get_post_type( $the_id ), $the_id, 'loop-search' );
  135.  
  136.                         if( ! empty( $taxonomies ) )
  137.                         {
  138.                             foreach( $taxonomies as $taxonomy )
  139.                             {
  140.                                 if( ! in_array( $taxonomy, $excluded_taxonomies ) )
  141.                                 {
  142.                                     $cats .= get_the_term_list( $the_id, $taxonomy, '', ', ','' ) . ' ';
  143.                                 }
  144.                             }
  145.                         }
  146.  
  147.                         if( 'blog-meta-category' == avia_get_option( 'blog-meta-category' ) )
  148.                         {
  149.                             if( ! empty( $cats ) )
  150.                             {
  151.                                 $meta_cats  = '<span class="blog-categories minor-meta">' . __( 'in', 'avia_framework') . ' ';
  152.                                 $meta_cats .=   trim( $cats );
  153.                                 $meta_cats .= '</span>';
  154.  
  155.                                 $meta_info['categories'] = $meta_cats;
  156.                             }
  157.                         }
  158.  
  159.                         /**
  160.                          * Allow to change theme options setting for certain posts
  161.                          *
  162.                          * @since 4.8.8
  163.                          * @param boolean $show_author_meta
  164.                          * @param string $context
  165.                          * @return boolean
  166.                          */
  167.                         if( true === apply_filters( 'avf_show_author_meta', 'blog-meta-author' == avia_get_option( 'blog-meta-author' ), 'loop-search' ) )
  168.                         {
  169.                             $meta_author  = '<span class="blog-author minor-meta">' . __( 'by', 'avia_framework' ) . ' ';
  170.                             $meta_author .=     '<span class="entry-author-link" ' . avia_markup_helper( array( 'context' => 'author_name', 'echo' => false ) ) . '>';
  171.                             $meta_author .=         '<span class="author">';
  172.                             $meta_author .=             '<span class="fn">';
  173.                             $meta_author .=                 get_the_author_posts_link();
  174.                             $meta_author .=             '</span>';
  175.                             $meta_author .=         '</span>';
  176.                             $meta_author .=     '</span>';
  177.                             $meta_author .= '</span>';
  178.  
  179.                             $meta_info['author'] = $meta_author;
  180.                         }
  181.  
  182.                         /**
  183.                          * Modify the post metadata array
  184.                          *
  185.                          * @since 4.8.8
  186.                          * @param array $meta_info
  187.                          * @param string $context
  188.                          * @return array
  189.                          */
  190.                         $meta_info = apply_filters( 'avf_post_metadata_array', $meta_info, 'loop-search' );
  191.  
  192.                         echo implode( $meta_separator, $meta_info );
  193.  
  194.                     echo '</span>';
  195.                 echo '</header>';
  196.  
  197.                 echo '<div class="entry-content" ' . avia_markup_helper( array( 'context' => 'entry_content','echo' => false ) ) . '>';
  198.  
  199.                     $excerpt = trim( get_the_excerpt() );
  200.                     if( ! empty( $excerpt ) )
  201.                     {
  202.                         the_excerpt();
  203.                     }
  204.                     else
  205.                     {
  206.                         $excerpt = strip_shortcodes( get_the_content() );
  207.                         $excerpt = apply_filters( 'the_excerpt', $excerpt );
  208.                         $excerpt = str_replace( ']]>', ']]&gt;', $excerpt );
  209.                         echo $excerpt;
  210.                     }
  211.  
  212.                 echo '</div>';
  213.             echo '</div>';
  214.  
  215.             echo '<footer class="entry-footer"></footer>';
  216.  
  217.             do_action('ava_after_content', $the_id, 'loop-search' );
  218.  
  219.         echo '</article><!--end post-entry-->';
  220.  
  221.         $first = false;
  222.         $post_loop_count++;
  223.  
  224.         if( $post_loop_count >= 100 )
  225.         {
  226.             $counterclass = 'nowidth';
  227.         }
  228.     }
  229. }
  230. else
  231. {
  232. ?>
  233.     <article class="entry entry-content-wrapper clearfix" id='search-fail'>
  234.         <p class="entry-content" <?php avia_markup_helper( array( 'context' => 'entry_content' ) ); ?>>
  235.             <strong><?php _e('Nothing Found', 'avia_framework'); ?></strong><br/>
  236. <?php
  237.                 _e( 'Sorry, no posts matched your criteria. Please try another search', 'avia_framework' );
  238. ?>
  239.         </p>
  240.         <div class='hr_invisible'></div>
  241.         <section class="search_not_found">
  242.             <p><?php _e( 'You might want to consider some of our suggestions to get better results:', 'avia_framework' ); ?></p>
  243.             <ul>
  244.                 <li><?php _e( 'Check your spelling.', 'avia_framework' ); ?></li>
  245.                 <li><?php _e( 'Try a similar keyword, for example: tablet instead of laptop.', 'avia_framework' ); ?></li>
  246.                 <li><?php _e( 'Try using more than one keyword.', 'avia_framework' ); ?></li>
  247.             </ul>
  248. <?php
  249.         /**
  250.          * Additional output when nothing found in search
  251.          *
  252.          * @since 4.1.2
  253.          * @added_by günter
  254.          * @return string           cutom HTML escaped for echo | ''
  255.          */
  256.         $custom_no_earch_result = apply_filters( 'avf_search_results_pagecontent', '' );
  257.         echo $custom_no_earch_result;
  258.  
  259.  
  260.         echo '</section>';
  261.     echo '</article>';
  262.  
  263. }
  264.  
  265. echo avia_pagination( '', 'nav' );
  266.  
  267.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement