简体   繁体   English

WordPress的:主页导航搞砸了

[英]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). 如果滚动,则到达底部时,您会注意到一个链接,该链接将继续进行页面导航(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. 如果您访问website.com/page/6/,您仍然会获得首页帖子。

Here's the index.php. 这是index.php。 What's wrong with it? 它出什么问题了? :o :o

PS: Wordpress latest version. PS: Wordpress最新版本。 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 问题是,当您转到第2、3等页时,一切都被搞砸了:D

The reason the pagination is not working is that you have not added the correct parameters to the query_posts function. 分页不起作用的原因是您没有向query_posts函数添加正确的参数。

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

But you need to add the paged parameter too. 但是您也需要添加paged参数。 You may also want to add posts_per_page 您可能还想添加posts_per_page

See the Wordpress codex: http://codex.wordpress.org/Function_Reference/query_posts#Pagination 请参阅Wordpress编解码器: 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 另请参阅以获取分页参数: 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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