Wordpress:主页导航搞砸了

时间:2013-06-15 23:51:10

标签: php wordpress navigation pagination

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

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

P.S。: 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

1 个答案:

答案 0 :(得分:0)

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

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

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

请参阅Wordpress codex: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);