0

是我正在谈论的网站。如果您滚动,当您到达底部时,您会注意到一个链接继续进行页面导航(Pagina successiva)。如果您单击它,您将获得与主页相同的帖子!它还在继续。如果您访问 website.com/page/6/,您仍然会看到主页帖子。

这是 index.php。它出什么问题了?:o

PS: Wordpress 最新版本。没有儿童主题。我创建的自定义一个:

<?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(); ?>

正如您在访问该站点时所看到的,在主页中有一个硬编码页面(它应该保留在每个下一页中,然后是不应出现在下一页中的“特色”帖子)。问题是当您转到第 2、3 页等时,一切都搞砸了:D

4

1 回答 1

0

分页不起作用的原因是您没有向query_posts函数添加正确的参数。

你有这个: query_posts( 'cat=-7' );

但是您也需要添加paged参数。您可能还想添加posts_per_page

请参阅 Wordpress 法典:http ://codex.wordpress.org/Function_Reference/query_posts#Pagination

另请参见获取分页参数:http ://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query

这是一个例子:

$args = array(
    'cat' => '-7',
    'posts_per_page' => 6,
    'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1 )
);
query_posts($args);
于 2013-06-16T03:22:38.203 回答