Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I load 10 posts on my home.php and I have the 'posts_nav_link()' function to acces to latest entries. But when I click on the previous entries, the link redirect me to mysite.com/page/2 and give me a 404 error.

Could you help me please Thanks ?

<?php if (have_posts()) : 
                query_posts(
                        array(
                            'post_type' => array(
                                'etude',
                                'new'
                            )
                        )
                    );?>


                <?php while (have_posts()) :
                    the_post(); ?>

                <div class="box1 clearfix" style="margin-top: 7px;">
                    <div class="post clearfix">
                        <h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
                        <p class="txt0"><?php the_time('d F Y'); ?> dans <a href="<?php echo site_url(get_post_type());?>"><?php echo get_post_type(); ?></a> // <?php comments_popup_link(__('No Comments &#187;', woothemes), __('1 Comment &#187;',woothemes), __('% Comments &#187;',woothemes)); ?></p>

                    <?php the_content(__('<span class="continue">Continue Reading</span>',woothemes)) ?>

                    </div>
                </div>

                <?php endwhile; ?>

                <div class="navigation nav clearfix">
                    <div class="fl"><?php posts_nav_link() ?></div>
                </div>
share|improve this question
    
We need more info. Can you show us the code that you are using for your home page? Also, double-check your permalink settings and try saving them again. –  Joseph Jul 2 '12 at 20:53
    
The posts_nav_link() redirect me to localhost/mysite/page/2 and give me a 404 error. –  Zaidar Jul 2 '12 at 20:57

1 Answer 1

up vote 3 down vote accepted

Never use query_posts() :). See this answer for more detailed explanation of why not, and the alternatives.

In this instance, remove your query_posts() and instead in a plug-in, (or functions php).

add_action('pre_get_posts','wpse57229_change_query_for_main_page');
function wpse57229_change_query_for_main_page( $query ){
     if( $query->is_main_query() && is_front_page() ){
          $query->set('post_type',array('etude','new'));
     }
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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