下一个分类页面404 wordpress自定义帖子类型
当我切换页面时,我正在创建自己的帖子类型(自定义帖子类型),并且出现错误。例如,当我打开一个类别时,它显示一个帖子,但是当我转到其他页面时,例如,第二个,它显示一个404(未找到)错误。下一个分类页面404 wordpress自定义帖子类型
页没有错误 - WWW *****,错误/分类/ CAT-名称/
页 - WWW ***** /分类/ CAT-名称/页/ 2
这是我的分类法portfolio_categories.php文件
<div class="container page min-height">
<div class="row works infinite-container">
<div class="col-md-12 category-menu">
<?php
$taxonomy = 'portfolio_categories';
$cat = get_the_terms($post->ID, $taxonomy);
foreach ($cat as $cat_slug){$category_slug = $cat_slug->slug;}
$terms = get_terms($taxonomy);
if ($terms && !is_wp_error($terms)) :
?>
<script>
$(document).ready(function(){
var categoryClass = '<?php echo $category_slug ?>';
$('.'+categoryClass).addClass('current');
});
</script>
<ul>
<?php foreach ($terms as $term) { ?>
<li class="<?php echo $term->slug; ?>"><a href="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?></a></li>
<?php } ?>
</ul>
<?php endif;?>
</div>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'portfolio',
'taxonomy' => $taxonomy,
'posts_per_page' => 2,
'portfolio_categories' => $category_slug,
'paged' => $paged
);
$temp = $wp_query; $wp_query= null;
$wp_query = new WP_Query($args);
while ($wp_query->have_posts()) : $wp_query->the_post();
$category = get_the_terms($post->ID, 'portfolio_categories');
?>
<div class="col-md-4 col-sm-6 col-xs-12 work">
<div class="placeholder">
<a href="<?php the_permalink(); ?>" class="work-link"></a>
<div class="work-overlay">
<div class="overlay-content">
<div class="category-name"><?php foreach ($category as $cat){echo $cat->name;}?></div>
<div class="work-title"><?php the_title(); ?></div>
</div>
</div>
<div class="work-thumb">
<div style="background-image:url('<?php echo wp_get_attachment_url(get_post_thumbnail_id($post->ID)); ?>')"></div>
</div>
</div>
</div>
<?php
endwhile;
if(have_posts() == NULL){
echo info("Sorry, but there is no content available at this time!");
}
?>
<?php
if (function_exists('custom_pagination')) {
custom_pagination($wp_query->max_num_pages,"",$paged);
}
?>
</div>
</div>
有我的分类学PHP和register_post_type
function create_portfolio_taxonomies() {
$labels = array(
'name' => _x('Portfolio Categories', 'taxonomy general name'),
'singular_name' => _x('Category', 'taxonomy singular name'),
'search_items' => __('Search Categories'),
'all_items' => __('All Categories'),
'parent_item' => __('Parent Category'),
'parent_item_colon' => __('Parent Category:'),
'edit_item' => __('Edit Category'),
'update_item' => __('Update Category'),
'add_new_item' => __('Add New Category'),
'new_item_name' => __('New Category Name'),
'menu_name' => __('Categories'),
);
$args = array(
'hierarchical' => true, // Set this to 'false' for non-hierarchical taxonomy (like tags)
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'cat', 'with_front' => false),
);
register_taxonomy('portfolio_categories', array('portfolio'), $args);
}
add_action('init', 'create_portfolio_taxonomies', 0);
function cptui_register_my_cpts_portfolio() {
/**
* Post Type: Portfolio.
*/
$labels = array(
"name" => __("Portfolio", ""),
"singular_name" => __("portfolio", ""),
"menu_name" => __("Portfolio", ""),
"all_items" => __("All portfolios", ""),
"edit_item" => __("Edit", ""),
"view_item" => __("View", ""),
"view_items" => __("View portfolio", ""),
"not_found" => __("Portfolio not found", ""),
);
$args = array(
"label" => __("Portfolio", ""),
"labels" => $labels,
"description" => "portfolio page",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => 'portfolio',
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
'rewrite' => array('slug' => 'cat', 'with_front' => false),
"query_var" => true,
"supports" => array("title", "editor", "thumbnail", "excerpt", "custom-fields", "multi-post-image"),
"taxonomies" => array("portfolio_categories"),
);
register_post_type("portfolio", $args);
}
add_action('init', 'cptui_register_my_cpts_portfolio');
分页功能
function custom_pagination($numpages = '', $pagerange = '', $paged='') {
if (empty($pagerange)) {
$pagerange = 5;
}
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
$pagination_args = array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'total' => $numpages,
'current' => $paged,
'show_all' => False,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => True,
'prev_text' => __('«'),
'next_text' => __('»'),
'type' => 'plain',
'add_args' => false,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<nav class='pagination'>";
echo $paginate_links;
echo "</nav>";
}
}
从重写选项中删除slug => 'category'
,它应该是工作。
那不是问题 –
即时更新我的帖子与taxonomy-portfolio_categories.php –
此代码完美地为我工作。如果仍有问题,请尝试将固定链接设置更改为“发布名称”。
function create_portfolio_taxonomies() {
$labels = array(
'name' => _x('Portfolio Categories', 'taxonomy general name'),
'singular_name' => _x('Category', 'taxonomy singular name'),
'search_items' => __('Search Categories'),
'all_items' => __('All Categories'),
'parent_item' => __('Parent Category'),
'parent_item_colon' => __('Parent Category:'),
'edit_item' => __('Edit Category'),
'update_item' => __('Update Category'),
'add_new_item' => __('Add New Category'),
'new_item_name' => __('New Category Name'),
'menu_name' => __('Categories'),
);
$args = array(
'hierarchical' => true, // Set this to 'false' for non-hierarchical taxonomy (like tags)
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array('slug' => 'portfolio-category', 'with_front' => false),
);
register_taxonomy('portfolio_categories', array('portfolio'), $args);
flush_rewrite_rules();
}
add_action('init', 'create_portfolio_taxonomies', 0);
function cptui_register_my_cpts_portfolio() {
/**
* Post Type: Portfolio.
*/
$labels = array(
"name" => __("Portfolio", ""),
"singular_name" => __("portfolio", ""),
"menu_name" => __("Portfolio", ""),
"all_items" => __("All portfolios", ""),
"edit_item" => __("Edit", ""),
"view_item" => __("View", ""),
"view_items" => __("View portfolio", ""),
"not_found" => __("Portfolio not found", ""),
);
$args = array(
"label" => __("Portfolio", ""),
"labels" => $labels,
"description" => "portfolio page",
"public" => true,
"publicly_queryable" => true,
"show_ui" => true,
"show_in_rest" => false,
"rest_base" => "",
"has_archive" => 'portfolio',
"show_in_menu" => true,
"exclude_from_search" => false,
"capability_type" => "post",
"map_meta_cap" => true,
"hierarchical" => false,
'rewrite' => array('slug' => 'portfolio', 'with_front' => false),
"query_var" => true,
"supports" => array("title", "editor", "thumbnail", "excerpt", "custom-fields", "multi-post-image"),
"taxonomies" => array("portfolio_categories"),
);
register_post_type("portfolio", $args);
flush_rewrite_rules();
}
add_action('init', 'cptui_register_my_cpts_portfolio');
- 改写塞“类别”默认使用后的类别,这就是为什么可能是你所得到的404错误。
我替换此代码并设置永久链接设置为“发布名称”,但仍然是相同的错误。也许我的分页有错误?我把它添加到我的帖子 –
即时更新我的帖子与taxonomy-portfolio_categories.php –
我已经测试这个代码在我的本地服务器,并完美工作。可能会有任何插件影响到这一点。尝试将永久链接链接更改为默认链接,然后再次更改为漂亮链接。 –
你能把'with_front => false'设置为'with_front => true'吗? – justkidding96
@ justkidding96同样的错误 –
'/ category/cat-name/page/2'这是什么意思?这是否涉及第二页? – justkidding96