通常我会尽我所能通过搜索在线或无休止的实验来找到答案。这一次我真的很绝望。我已经阅读了许多相关的问题,但没有解决我的问题。Wordpress get_template_part不工作 - 返回404页面而不是loop-xxx.php
我在许多其他主题中使用'get_template_part',它运行良好。这次我不知道是什么造成了差异。
在我的主题中有一个注册的自定义帖子类型事件。活动中帖子的网址看起来像example.com/event/wine-tasting。
的问题是:example.com/event/返回一个404页面,而不是排队的所有事件的帖子(环event.php)
这里是我的archive.php:
<?php get_header(); ?>
<?php if (have_posts()) the_post();?>
<?php rewind_posts();?>
<?php $post_type = get_post_type();
get_template_part('loop', $post_type);?>
<?php get_footer(); ?>
这里是我的环event.php:
<?php get_header(); ?>
<?php if (have_posts()) while (have_posts()) : the_post(); ?>
<div class="container">
<?php the_title();?>
<?php the_content();?>
</div>
<?php endwhile; ?>
这是我如何注册自定义后类型“事件”:
function yd_create_post_type_event()
{
$labels = array(
'name' => __('Events','yd'),
'singular_name' => __('Event','yd'),
'add_new' => __('Add New','yd'),
'add_new_item' => __('Add New Event','yd'),
'edit_item' => __('Edit Event','yd'),
'new_item' => __('New Event','yd'),
'view_item' => __('View Event','yd'),
'search_items' => __('Search Event','yd'),
'not_found' => __('No event found','yd'),
'not_found_in_trash' => __('No event found in Trash','yd'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'query_var' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'menu_icon' => 0,
'supports' => array('title','editor','excerpt')
);
register_post_type('event',$args);
}
register_taxonomy(
"event-category",
array("event"),
array(
"hierarchical" => true,
"label" => __("Event Categories",'yd'),
"singular_label" => __("Event Category",'yd'),
"rewrite" => array('slug' => 'event')
)
);
我真的很感谢你的帮忙。我尝试过所有的事情,我希望是我犯了一些愚蠢的错误。但到目前为止我还无法解决这个问题。先谢谢你!
此问题已排序......基本上,我认为* example.com/event/*将返回loop-event.php,但实际上它应该是类似url * example.com/event-category/all-事件/ *等...大脑短路。 – 2013-03-22 21:09:07