cant figure out how to convert a query_posts to WP_Query
-
I have a query_posts working, but since its not a custom WP_Query like it needs to be the posts per page setting in the admin affects it. How can I change it to a custom query using WP_Query? I have never done it with displaying attachments. I have with displaying posts from a category like in the codex. I just need to display the latest 6 images from a specific post category (which it does). But my blog settings must be set to “Blog pages show at most 1” for it to work. If I change it to anything else it shows more than 6.
Thanks
<?php query_posts( array( 'category__and' => array(1), 'orderby' => 'title', 'order' => 'DESC' ) ); while ( have_posts() ) : the_post(); ?> <?php $args = array( 'post_type' => 'attachment', 'orderby' => 'menu_order', 'posts_per_page' => 6, 'order' => 'DESC', 'post_mime_type' => 'image', 'post_status' => null, 'post_parent' => $post->ID ); $images = get_posts($args); if ($images) { foreach ( $images as $image ) { ?> <a href="<?php echo wp_get_attachment_url( $image->ID , 'thumbnail' ); ?>" rel="lightbox"><div class="home-thumbs"><?php echo wp_get_attachment_image( $image->ID , 'thumbnail' ); ?></div><!--end home-thumbs--></a> <?php } } ?> <?php endwhile; // Reset Query wp_reset_query(); ?>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘cant figure out how to convert a query_posts to WP_Query’ is closed to new replies.