Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $post_cat = $category->taxonomy; // This will equal a custom category type.
- $post_term = $category->term_id; // This will equal the page's category id.
- // Sets the global $wpdb
- global $wpdb;
- // Starts the db query
- $query = "
- SELECT DISTINCT ID, guid, post_parent FROM $wpdb->term_taxonomy, $wpdb->terms, $wpdb->posts p where p.post_type = 'attachment'
- AND p.post_mime_type LIKE 'image/%'
- AND p.post_status = 'inherit'
- AND p.post_parent IN
- (SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = $post_term)
- AND $wpdb->term_taxonomy.taxonomy = '$post_cat'
- AND $wpdb->terms.term_id = $post_term
- ";
- $results = $wpdb->get_results( $query );
- if ( $results ) {
- shuffle($results);
- foreach ( (array) $results as $image ) {
- $url = get_attachment_link($image->post_parent);
- $thumb = wp_get_attachment_image( $image->ID, 'thumbnail', false );
- $alt = get_post_meta($image->ID, '_wp_attachment_image_alt', true);
- echo '<li style="display:inline-block;"><a href="' . get_permalink($image->post_parent) .'">' . $thumb . '</a></li>'."\n";
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment