-1

I'm trying for days how fix pagination on index of my wordpress site. Pagination work great on category and other archive but doesn't work on my index

clicking on the page numbers have a 404. I found that the links point to domain.com?paged=4. Replacing ?paged=4 with ?page=4 the pagination work!

<?php wp_reset_query(); ?>
                    <?php 
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args   =  array(
                    'post_type' => array(of_get_options( 'url_movie', 'movie') ),
                    'showposts' => get_option('posts_per_page '),
                    'order' => 'DESC',
                    'paged' => $paged

                ); 
            query_posts($args);
                while ( have_posts() ) : the_post(); ?>


<li class="item">
                <a class="poster" href="<?php the_permalink(); ?>" title="<?php if(show_info('name', $post->ID ) == "N/A"){echo show_info('title', $post->ID ); }else{echo show_info('name', $post->ID );} ?>">
                <img src="<?php image_show("poster_path", $post->ID, "w185"); ?>" alt="<?php if(show_info('name', $post->ID ) == "N/A"){echo show_info('title', $post->ID ); }else{echo show_info('name', $post->ID );} ?>" />              
                </a>
                <div class="info">
                <h3 class="name"><a href="<?php the_permalink(); ?>" title="<?php if(show_info('name', $post->ID ) == "N/A"){echo show_info('title', $post->ID ); }else{echo show_info('name', $post->ID );} ?>"><?php if(show_info('name', $post->ID ) == "N/A"){echo show_info('title', $post->ID ); }else{echo show_info('name', $post->ID );} ?></a></h3>
                <span class="genero"><?php $category = get_the_category($post->ID); echo $category[0]->cat_name; ?></span>
                </div> 
            </li>  
            <?php endwhile; ?>

            </ul>
            <div class="clear"></div>

          <?php  if(function_exists('wp_paginate')) {
    wp_paginate();
}
else {
    pagenavi();
} ?> 
  • What do you mean by "it doesn't work"? What have you tried, what worked, what didn't work? Please update your post with (a lot) more information. – engelen Mar 30 '16 at 14:18
  • clicking on the page numbers have a 404. I found that the links point to domain.com?paged=4. Replacing ?paged=4 with ?page=4 the pagination work! – Riccardo Costantini Mar 30 '16 at 14:28
  • 1
    There are more than enough resources on site as to why to NEVER EVER use query_posts. You should be using pre_get_posts to alter the main query to your needs, which there are also enough resources on site – Pieter Goosen Mar 30 '16 at 15:23
  • pagenavi() and wp_paginate() both functions are not from WordPress, query var is wrong, query_posts is a bad practice. – Sumit Mar 30 '16 at 15:38
  • You can find out about Pagination on the WordPress CodeX and also you can see every function that WordPress has to offer by visiting Function Reference on the WordPress CodeX – Stephen Apr 6 '16 at 22:06
0

The reasons why you should not run query_posts() are perfectly outlined in this answer. Long story short: You overwrite the default query (that happens by WP core) and replace everything that was valid for this request with data that only matches for your secondary query.

  • The function get_query_var() relies on the global $wp_query that gets reset by your query_posts() call. This is what happens inside this function:

    $GLOBALS['wp_query']->get( $var, $default );
    
  • The wp_reset_query() function, does re-sync $wp_query with $wp_the_query. This is what happens in its core:

    $GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
    

    More details about the how can found in this answer.

Answer: Basically you are nuking all the globals that WordPress relies on. And as plugins need to rely on WP core, you nuke that one as well.

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.