Problem : I'm trying to display few post on my WP front page, so I used query_post to get post using some filtering argument and it's giving perfect result. Problem happens when pagination added in this query. First page is showing without any issue but res from page 2 to end it's just shown a 404 page. If I use same code on another page instead of front page or index.php it's working fine. The same code also worked on any templates also.

Spec : WP 3.9, xaamp / online server php 5.3

Solution Tried :

  1. making $paged global, failed.
  2. using pagination plugin, failed.
  3. using custom pagination designed by me, failed.
  4. using page if paged variable not exists, failed.
  5. using wp_query, failed.

    <?php
        // Get all posts under category testimonials.
        // The Query
        global $paged;
        $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $wp_query = new WP_Query();
          $wp_query->query('showposts=2'.'&paged='.$paged);
          /*query_posts( array (
          'posts_per_page' => 2,
          'paged' => $paged
          ) );*/
          // The Loop
          if ( have_posts() ) : while ( have_posts() ) : the_post(); $post_id =get_the_ID();
     ?>
    
有帮助吗?

解决方案

if you use static front page then, use get_query_var('page') instead of get_query_var('paged'). hope it will work!

$paged = (get_query_var('page')) ? get_query_var('page') : 1;

其他提示

Try this

global $query_string;
    parse_str( $query_string, $my_query_array );
    $paged = ( isset( $my_query_array['paged'] ) && !empty( $my_query_array['paged'] ) ) ? $my_query_array['paged'] : 0;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top