Reputation: 398
<?php //
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query(); $wp_query->query('showposts=3' . '&paged='.$paged);
?>
<ul class="column-three">
<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>" id="post-<?php the_ID(); ?>">
<?php if (has_post_thumbnail()){ the_post_thumbnail('post-thumbnails'); } else {echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/b.jpg'. '"/>'; }?>
<span class="title"><?php the_title(); ?></span>
<span class="incrypt"><?php $excerpt = get_the_excerpt(); echo string_limit_words($excerpt,30); ?></span>
<span class="read-more">Read More</span>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php wp_reset_postdata(); ?>
before code above is working until wordpress updates, my problem is the number of post display must be 3 post only but it display more than 3 is there any hope or is there something messing in my code above
Upvotes: 0
Views: 78
Reputation: 1545
Try With this.
<?php
$args = array(
'post_type' => 'post',
'post_status' => 'publish',
'posts_per_page' => '-1'
);
$query = new WP_Query ($args );
while ( $query->have_posts() ): $query->the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php endwhile; wp_reset_postdata();
?>
Upvotes: 0
Reputation: 962
Your Code is working for me and I have make page-test.php and get posts in that page and "showposts" working for me still use "posts_per_page" as mentioned by @jogesh_pi comment and also try below code that will also get posts by get_posts function.
$post_list = get_posts( array(
'post_type' => 'post',
'numberposts' => 3,
'orderby' => 'menu_order',
'sort_order' => 'asc'
) );
?>
<ul class="column-three">
<?php foreach ( $post_list as $post ) { ?>
<li>
<a href="<?php the_permalink(); ?>" id="post-<?php $post->ID; ?>">
<?php if (has_post_thumbnail($post->ID)){ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
?>
<img src="<?php echo $image[0]; ?>"/>
<?php
} else {echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/b.jpg'. '"/>'; }?>
<span class="title"><?php echo $post->post_title; ?></span>
<span class="incrypt"><?php $excerpt = $post->post_excerpt; echo substr( $excerpt , 0, 30);?></span>
<span class="read-more">Read More</span>
</a>
</li>
<?php } ?>
</ul>
<?php
wp_reset_postdata();
Upvotes: 0
Reputation: 9782
Well, the showposts
parameter is replaced with posts_per_page
. So try with
$wp_query->query('posts_per_page=3' . '&paged='.$paged);
You could use:
$args = array(
'posts_per_page' => 3,
'paged' => $paged,
);
$query = new WP_Query( $args );
Upvotes: 2