【问题标题】:Wordpress custom post type pagination 404 page 2Wordpress 自定义帖子类型分页 404 第 2 页
【发布时间】:2014-07-12 15:43:02
【问题描述】:

我是新手,我正在尝试开发我的第一个主题。

不幸的是,我在使用自定义帖子类型 (projet) 时遇到了一些问题。我尝试了关于这个主题的不同组合(query_post、WP_Query、刷新永久链接等),但似乎没有一个对我有用。

我尝试使用插件 wp_pagenavi。

这是我的注册帖子类型,在 function.php 中:

register_post_type('projet', array(
    'label' => __('Réalisations'),
    'singular_label' => __('Projet'),
    'public' => true,
    'show_ui' => true,
    'rewrite' => array('slug' => 'international/realisations', 'with_front' => true),
    'hierarchical' => false,
    'has-archive' => true,
    'query_var' => true,
    'supports' => array('title', 'excerpt', 'editor', 'thumbnail', 'page-attributes')
));

这是模板中列出我的自定义帖子类型“projet”的代码:

 <ul id="list-projets" class="grid cs-style-7">
        <?php if ( get_query_var('paged') ) {
            $paged = get_query_var('paged');
        } else if ( get_query_var('page') ) {
            $paged = get_query_var('page');
        } else {
            $paged = 1;
        } ?>
            <?php
            $args= array(
                        'showposts' => 2,
                        'posts_per_page' => 2,
                        'post_type'  => 'projet',
                        'paged' => $paged
                        );
            $the_query = new WP_Query($args);

            if ($the_query->have_posts()): while ($the_query->have_posts()) : $the_query->the_post(); ?> 

              <li>
                    <figure>
                        <?php the_post_thumbnail(); ?>
                        <h3><?php the_title(); ?></h3>
                        <figcaption>
                            <span><?php echo get_the_excerpt(); ?></span>
                            <a href="<?php the_permalink(); ?>">+ de détails</a>
                        </figcaption>
                    </figure>
                </li>

            <?php endwhile; ?>    
            <?php endif; 
            wp_reset_query(); ?>
            <nav>
                <?php wp_pagenavi( array( 'query' => $the_query ) ); ?>
            </nav>
    </ul>

目前,此代码列出了 2 个最后一个自定义帖子类型“projet”和分页,但如果我单击第 2 页,它会显示 404 错误。网址是 /localhost/wordpress/international/realisations/page/2/

我尝试将 'has_archive' => true 添加到我的注册帖子类型,但是当我保存并刷新永久链接并返回到我的列表页面 /localhost/wordpress/international/realisations/ 页面是空的,我的面包屑是没有更好的“ACCUEIL > RÉALISATIONS”而不是“ACCUEIL > INTERNATIONAL > RÉALISATIONS”。

我是新手,所以也许我做错了什么,请帮助我,因为我已经搜索了几天,我不知道该怎么办!

我还在link 测试了这个解决方案(仍然是 404)。

【问题讨论】:

标签: wordpress pagination http-status-code-404 custom-post-type


【解决方案1】:

这个

<nav>
    <?php wp_pagenavi( array( 'query' => $the_query ) ); ?>
</nav>

使用这个

<div class="pagination">
<?php             
    global $wp_query;

    $big = 999999999; // need an unlikely integer

    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages
    ) );
?>
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-22
    • 2015-06-07
    • 2014-05-15
    • 2011-03-20
    • 2014-05-21
    • 2020-03-22
    • 2014-03-24
    相关资源
    最近更新 更多