Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. <?php get_header(); ?>
  2.  
  3. <div id="main-content">
  4. <div class="container">
  5. <div id="content-area" class="clearfix">
  6. <div id="left-area" >
  7. <?php
  8. global $wpdb;
  9. $s = (isset($_GET['s']) && $_GET['s']) ? urldecode($_GET['s']) : false;
  10.  
  11. if($s){
  12. $where = ' title LIKE \'%' . esc_sql( like_escape($s) ) . '%\'';
  13.  
  14. $arr_title = explode(' ',$s);
  15. foreach($arr_title as $search_term):
  16. $where .= ' OR title LIKE \'%' . esc_sql( like_escape( $search_term ) ) . '%\'';
  17. endforeach;
  18.  
  19.  
  20. $query = "
  21. SELECT *
  22. FROM ( SELECT p.ID as id, p.post_title as title, p.post_name as slug, p.post_excerpt as excerpt, 'post' AS type FROM $wpdb->posts AS p WHERE p.post_type IN ('post', 'page', 'product') AND p.post_status = 'publish'
  23. UNION ALL
  24. SELECT t.term_id as id, t.name as title, t.slug as slug, tx.description as excerpt, 'term' AS type FROM $wpdb->terms AS t LEFT JOIN $wpdb->term_taxonomy AS tx ON t.term_id = tx.term_id WHERE tx.taxonomy NOT IN ('product_tag', 'post_tag')
  25. ) AS tb WHERE $where ";
  26.  
  27.  
  28. //start pagination
  29. $results = $wpdb->get_results($query);
  30. $total = count($results);
  31. $paged = (isset($_GET['paged'])) ? $_GET['paged'] : 1;
  32. $limit = 50;
  33. //end pagination
  34.  
  35. $offset = $paged ? ($paged - 1) * $limit : 0;
  36. $results = $wpdb->get_results( $query . " LIMIT $offset, $limit ");
  37.  
  38.  
  39. if ($results) :
  40. foreach( $results as $row ) :
  41. $url_img = false; $permalink = false;
  42. if($row->type=='post'){
  43. // $url_img = wp_get_attachment_url( $attachment_id, 'small');
  44. $result = wp_get_attachment_image_src ($attachment_id, 'medium');
  45. $url_img = $result['url'];
  46.  
  47. $permalink = get_permalink($row->id);
  48. }
  49. if($row->type=='term'){
  50. $permalink = get_bloginfo('url').'/products/'.$row->slug;
  51. }
  52.  
  53. ?>
  54.  
  55. <article id="post-<?php echo $row->id; ?>" class="et_pb_post post-<?php echo $row->id; ?>">
  56.  
  57. <?php if($url_img): ?>
  58. <a href="<?php echo $permalink; ?>"><img src="<?php echo $url_img; ?>" alt="<?php echo $row->title; ?>" /> </a>
  59. <?php endif; ?>
  60.  
  61. <h2 class="entry-title"><a href="<?php echo (!is_wp_error($permalink)) ? $permalink : '#'; ?>"><?php echo $row->title; ?></a></h2>
  62. <?php echo $row->excerpt; ?>
  63. <div class="read-more-link-container"><a href="<?php echo (!is_wp_error($permalink)) ? $permalink : '#'; ?>" class="read-more-link"> Read More</a></div>
  64. </article>
  65.  
  66.  
  67.  
  68. <?php endforeach;
  69.  
  70. if($total > $limit):
  71. $pl_args = array(
  72. 'base' => add_query_arg('paged','%#%'),
  73. 'format' => '',
  74. 'total' => ceil($total / $limit),
  75. 'current' => max(1, $paged),
  76. );
  77. echo paginate_links($pl_args);
  78. endif;
  79.  
  80. else : get_template_part( 'includes/no-results', 'index' );
  81. endif;
  82. }else{
  83. get_template_part( 'includes/no-results', 'index' );
  84. }
  85. ?>
  86. </div> <!-- #left-area -->
  87.  
  88. <?php get_sidebar('search'); ?>
  89. </div> <!-- #content-area -->
  90. </div> <!-- .container -->
  91. </div> <!-- #main-content -->
  92.  
  93. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement