<!-- Table for equal height always --> <table id="sthlm_img_table"> <tr> <!-- Gallery images --> <td class="sthlm-images-container" id="sthlm_current_gallery_images"> </td> <!-- All images --> <td class="sthlm-images-container" id="sthlm_all_images"> <?php $args = array('post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => 32, 'orderby' => 'menu_order', 'order' => 'ASC'); $images = get_posts($args); // print most images if (!empty($images)) { foreach ((array) $images as $img) { sthlm_img_thumb_template($img); } } else { _e('Inga bilder existerar.', 'sthlm_gallery'); } ?> </td> </tr> </table> </div>
function sthlm_gallery_query_attachments() { $args['post_type'] = 'attachment'; $args['post_mime_type'] = 'image'; $args['numberposts'] = -1; $args['orderby'] = 'menu_order'; $args['order'] = 'ASC'; // Query images by date if ($_GET['context'] == 'wpsthlm-date') { $q = explode('/', $_GET['query']); if ($q[0]) { $args['year'] = $q[0]; } if ($q[1]) { $args['monthnum'] = (int) $q[1]; } $images = get_posts($args); // Query images by searchterm } elseif ($_GET['context'] == 'wpsthlm-filter') { $q = $_GET['query']; $posts = array(); // skapa arrayen om den skulle vara tom vid implode vilket innebär error // SPATHON global $wpdb; /* * * Rätt tabell prefix i databasen nu krävs att man har wp_ * $wpdb->prefix = prefix * $wpdb->posts = wp_posts * * Prepare för säkerheten * %s = string * %d = int * * // SPATHON */ $q = "%" . $q . "%"; $res = $wpdb->get_results($wpdb->prepare("SELECT ID\n\t\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\t\tWHERE post_excerpt LIKE '%s'\n\t\t\t\t\tOR post_title LIKE '%s'\n\t\t\t\t\tOR post_content LIKE '%s'\n\t\t\t\t\tAND post_type = 'attachment'", $q, $q, $q)); foreach ($res as $r) { $posts[] = $r->ID; } #echo '<pre>'; print_r($posts); echo '</pre>'; #die(); if (count($posts) == 0) { die; } $args['include'] = implode($posts, ','); $images = get_posts($args); } $i = 0; // loop all images if (!empty($images)) { foreach ((array) $images as $img) { // echo the thumbs sthlm_img_thumb_template($img); // templates.php } } else { _e('Inga bilder existerar', 'sthlm_gallery'); } exit; }