简体   繁体   中英

Wordpress: home page navigation screwed

Here 's the website I'm talking about. If you scroll, when you reach the bottom you'll notice a link to go on with the page navigation (Pagina successiva). If you click it you'll get the same posts as the ones in home page! And it goes on. If you visit website.com/page/6/ you still get the home page posts.

Here's the index.php. What's wrong with it? :o

PS: Wordpress latest version. No child theme. Custom one I created:

<?php get_header(); ?>

<?php if (is_home() && !is_paged()) { ?>

    <!-- editoriale -->
    <div id="editoriale">
        <?php $my_query = new WP_Query('cat=10&showposts=1');
            while ($my_query->have_posts()) : $my_query->the_post();
            $do_not_duplicate = $post->ID; ?>
        <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
        <div class="postinfo" style="margin-top:-10px">
            di <a href="<?php echo get_option('home'); ?>/author/<?php the_author_meta( user_nicename ); ?>/"><?php the_author(); ?></a> - 
            pubblicato il <?php the_time('j F Y') ?> - 
            <?php comments_popup_link('nessun commento &#187;', '1 commento &#187;', '% commenti &#187;'); ?>
            <?php edit_post_link('modifica',' - [ ',' ]'); ?>
        </div>
        <div id="editoriale-cont" class="entry">
            <?php the_content(' Leggi il resto &raquo;'); ?>
        </div>
        <div class="postinfo" style="text-align:right;margin-top:10px">
            <a href="<?php echo get_option('home'); ?>/categoria/editoriali/">Tutti gli editoriali &raquo;</a>
        </div>
        <?php edit_post_link('Modifica', ' <div class="edit">', '</div>'); ?>
        <?php endwhile; ?>
    </div>
    <!-- fine editoriale -->

    <div class="hotnews" id="bombacalendario">
        <div style="padding:10px 0 15px 10px">
        <?php $my_query = new WP_Query( 'page_id=18570' );
            while ($my_query->have_posts()) : $my_query->the_post();
            $do_not_duplicate2[] = $post->ID;?>
                <h3><?php the_title(); ?></h3>
                <div><?php the_content(); ?></div>
                <?php edit_post_link('Modifica', ' <div class="edit">', '</div>'); ?>
            <?php endwhile; ?>
        </div>
    </div>
    <div style="margin-top:12px;padding-bottom:6px" id="cerca" class="hotnews">
        <h3>Cerca nel sito</h3><p>
        <form action="<?php echo get_option('home'); ?>/" id="searchform" method="get">
            <p><input type="text" style="width:135px;margin-right:10px" value="" name="s" id="s"><input type="submit" value="Vai" id="searchsubmit"></p>
        </form>
    </div>
    <div class="fine-blocco"></div>

<?php } ?>

<?php get_sidebar(); ?>

<!-- inizio contenuto -->
    <div id="content">
        <!-- post del blog -->
        <?php query_posts( 'cat=-7' );
        if (have_posts()) : while (have_posts()) : the_post();
            if( $post->ID == $do_not_duplicate ) continue; ?>

                <div class="post" id="post-<?php the_ID(); ?>">
                    <h2><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>
                    <div class="postinfo">
                        di <a href="<?php echo get_option('home'); ?>/author/<?php the_author_meta( user_nicename ); ?>/"><?php the_author(); ?></a> - 
                        pubblicato il <?php the_time('j F Y') ?><?php edit_post_link('modifica',' - [ ',' ]'); ?> - 
                        <?php comments_popup_link('nessun commento &#187;', '1 commento &#187;', '% commenti &#187;'); ?>
                    </div>
                    <div class="entry">
                        <?php the_content('[Continua &raquo;]'); ?>
                    </div>
                </div><br style="clear:both">
                <!-- fine post -->

        <?php endwhile; else: ?>
        <p><?php 'Spiacente, nessun risultato.'; ?></p>
        <?php endif;?>

        <p class="navigation">
        <?php posts_nav_link(' - ', '&laquo; Pagina Precedente', 'Pagina Successiva &raquo;'); ?>
        </p>

    </div>
<!-- fine contenuto -->

<?php get_footer(); ?>

As you can see visiting the site, in the home page there's an hardcoded page (which remains in every next page, as it should, and then a "featured" post which shouldn't appear in next page). Problem is everything is screwed when you go to page 2, 3, etc :D

The reason the pagination is not working is that you have not added the correct parameters to the query_posts function.

You have this: query_posts( 'cat=-7' );

But you need to add the paged parameter too. You may also want to add posts_per_page

See the Wordpress codex: http://codex.wordpress.org/Function_Reference/query_posts#Pagination

Also see this for getting the paged parameter: http://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query

Here is an example:

$args = array(
    'cat' => '-7',
    'posts_per_page' => 6,
    'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 )
);
query_posts($args);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM