Guenni007

loop-search

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