dqrnsg6439 2013-06-15 23:51 采纳率: 100%
浏览 31
已采纳

Wordpress:主页导航搞砸了

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

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

  • 写回答

1条回答 默认 最新

  • duanchun1852 2013-06-16 03:22
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行