通常我會盡我所能通過搜索在線或無休止的實驗來找到答案。這一次我真的很絕望。我已經閱讀了許多相關的問題,但沒有解決我的問題。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