Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. <form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
  2. <input type="text" name="s" id="s" value="Search..." onfocus="if (this.value=='Search...') this.value='';" onblur="if (this.value=='') this.value='Search...';" />
  3. <?php
  4. $parent = get_cat_ID("Pictures");
  5. ?>
  6. <input type="hidden" name="cat" value="<?php echo $parent; ?>" />
  7. <input type="submit" id="searchsubmit" value="" />
  8. </form>
  9.  
  10. <?php
  11. $args = array(
  12. 'post_type' => 'attachment',
  13. 'numberposts' => '-1',
  14. 'category_name' => get_the_title()
  15. );
  16. $images = get_posts($args);
  17. if (!empty($images)) {
  18. ?>
  19.  
  20. <?php
  21. $limit = 5;
  22.  
  23. $total = count($images);
  24. $pages = ceil($total / $limit);
  25. $result = ceil($total / $limit);
  26.  
  27. $current = isset($_GET['paged']) ? $_GET['paged'] : 1;
  28. $next = $current < $pages ? $current + 1 : null;
  29. $previous = $current > 1 ? $current - 1 : null;
  30.  
  31. $offset = ($current - 1) * $limit;
  32. $images = array_slice($images, $offset, $limit)
  33. ?>
  34.  
  35. <h4><span>Search</span> Results</h4>
  36. <ul class="category">
  37. <?php
  38. foreach ($images as $image) {
  39. $title = $image->post_title;
  40. $description = $image->post_content;
  41. $attachment_link = get_attachment_link( $image->ID );
  42. ?>
  43. <li>
  44. <div class="col1">
  45. <a href="<?php echo $attachment_link; ?>"><?php echo wp_get_attachment_image($image->ID, "medium"); ?></a>
  46. </div>
  47. <div class="col2">
  48. <h5><?php echo $title; ?></h5>
  49. <p><?php echo $description; ?></p>
  50. </div>
  51. </li>
  52. <?php } ?>
  53. </ul>
  54.  
  55. <?php echo "<p>(Page: ". $current . " of " . $result .")</p>"; ?>
  56. <? if($previous): ?>
  57. <a href="<?php bloginfo('url'); ?>?paged<?= $previous ?>">Previous</a>
  58. <? endif ?>
  59. <? if($next) : ?>
  60. <a href="<?php bloginfo('url'); ?>?paged<?= $next ?>">Next</a>
  61. <? endif ?>
  62. <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement