Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form method="get" id="searchform" action="<?php bloginfo('url'); ?>">
- <input type="text" name="s" id="s" value="Search..." onfocus="if (this.value=='Search...') this.value='';" onblur="if (this.value=='') this.value='Search...';" />
- <?php
- $parent = get_cat_ID("Pictures");
- ?>
- <input type="hidden" name="cat" value="<?php echo $parent; ?>" />
- <input type="submit" id="searchsubmit" value="" />
- </form>
- <?php
- $args = array(
- 'post_type' => 'attachment',
- 'numberposts' => '-1',
- 'category_name' => get_the_title()
- );
- $images = get_posts($args);
- if (!empty($images)) {
- ?>
- <?php
- $limit = 5;
- $total = count($images);
- $pages = ceil($total / $limit);
- $result = ceil($total / $limit);
- $current = isset($_GET['paged']) ? $_GET['paged'] : 1;
- $next = $current < $pages ? $current + 1 : null;
- $previous = $current > 1 ? $current - 1 : null;
- $offset = ($current - 1) * $limit;
- $images = array_slice($images, $offset, $limit)
- ?>
- <h4><span>Search</span> Results</h4>
- <ul class="category">
- <?php
- foreach ($images as $image) {
- $title = $image->post_title;
- $description = $image->post_content;
- $attachment_link = get_attachment_link( $image->ID );
- ?>
- <li>
- <div class="col1">
- <a href="<?php echo $attachment_link; ?>"><?php echo wp_get_attachment_image($image->ID, "medium"); ?></a>
- </div>
- <div class="col2">
- <h5><?php echo $title; ?></h5>
- <p><?php echo $description; ?></p>
- </div>
- </li>
- <?php } ?>
- </ul>
- <?php echo "<p>(Page: ". $current . " of " . $result .")</p>"; ?>
- <? if($previous): ?>
- <a href="<?php bloginfo('url'); ?>?paged<?= $previous ?>">Previous</a>
- <? endif ?>
- <? if($next) : ?>
- <a href="<?php bloginfo('url'); ?>?paged<?= $next ?>">Next</a>
- <? endif ?>
- <?php } ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement