【发布时间】: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)。
【问题讨论】:
-
大家好,我终于找到了适合我的解决方案:somadesign.ca/projects/smarter-custom-post-types
-
在您为自定义分类重写 slug 之前,这将不起作用。我遇到了同样的问题并给出了答案here on StackOverflow:
标签: wordpress pagination http-status-code-404 custom-post-type