1

the website i'm referring to is technibility.com. If you look at it the slider on top is using this piece of code

<?php if(is_home()) { ?>
<div id="ca-container" class="ca-container">
<div class="ca-wrapper">

<?php while (have_posts()): the_post(); ?>
<div class="ca-item ca-item-2">
<div class="ca-item-main">

<?php if (has_post_thumbnail()): ?>
<a href="<?php the_permalink(); ?>">
 <?php the_post_thumbnail(); ?>
</a>
<?php endif; ?>
               
<h3><a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a></h3>
</div>
</div>
<?php endwhile; ?>
</div>
</div>
<?php } ?>

problem is that if i used

query_posts('showposts=20');

its going to affect the entire site and show me 20 articles in the carousel and the posts on the page. How can i force it to only take affect with the slider?

also is there a way to have the_post_thumbnail() not stretch the image and use 150px height and any width but keeping it under 300px ?

1
  • 2
    query_posts() stomps on the whole global $query, so it is better to use WP_Query or get_posts(). Jul 19 '13 at 10:04
0

You need to pass an array to WP_Query like this

then after you've ended the query use this to reset the query data.

<?php wp_reset_query(); ?>

example of standard query using WP_Query

$arg = array(
'posts_per_page' => 20
);

$query = new WP_Query($args)
//start to loop your things here
 <?php if ($query->have_posts()) : ?>
 <?php while ($query->have_posts()) : $query->the_post(); ?>
// your custom code here
endif; endwhile;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.