May 24, 201214 yr Hello, I have made a custom post type which has some posts. However, after the first loop the content doubles. Here is the code (cut down): <? query_posts('post_type=client_wall'); ?> <?php while (have_posts()) : the_post(); ?> <div class="client floatleft"> <div class="client-title center-text georgia"> <? the_title(); ?> </div> <div class="client-area"> <div class="client-content floatleft georgia"> <? the_content(); ?> </div> <div class="client-image floatright"> <? the_post_thumbnail(); ?> </div> </div> </div> <?php endwhile;?> Any reason this would be happening? Edited May 24, 201214 yr by Alias
May 24, 201214 yr You say "the first loop" - if you're including multiple loops on a page, it's safest to instantiate a new WP_Query() for each rather than using query_posts, which just modifies and reruns the standard query for that page, assigning it to the standard $wp_query var. $args = array( 'post_type' => 'client_wall', ); $client_query = new WP_Query($args); while($client_query->have_posts()) : $client_query->the_post(); <div class="client floatleft"> <div class="client-title center-text georgia"> <?php the_title(); ?> </div> <div class="client-area"> <div class="client-content floatleft georgia"> <?php the_content(); ?> </div> <div class="client-image floatright"> <?php the_post_thumbnail(); ?> </div> </div> </div> <?php endwhile; ?> Another way of doing it would be to back up and restore $wp_query before and after your custom loop: <?php $temp = $wp_query; query_posts('post_type=client_wall'); ?> <?php while (have_posts()) : the_post(); ?> <div class="client floatleft"> <div class="client-title center-text georgia"> <?php the_title(); ?> </div> <div class="client-area"> <div class="client-content floatleft georgia"> <?php the_content(); ?> </div> <div class="client-image floatright"> <?php the_post_thumbnail(); ?> </div> </div> </div> <?php endwhile; $wp_query = $temp; ?> Couple of side points: Best not to use the short php opening tags. They might be supported on the host you're using, but a site may be moved to a different host in the future where they're not enabled. Your classes "center-text" and "georgia" are unsemantic - imagine the desired typeface changes in the future. Now elements with the class "georgia" are actually in Museo. Edited May 24, 201214 yr by Renaissance-Design
May 24, 201214 yr Author Ah thank you it worked And yeah, didn't really think about that tbh, cheers!
Create an account or sign in to comment