일반적으로 온라인 또는 끝없는 실험을 통해 답변을 찾으려고 최선을 다합니다. 이번엔 정말 필사적이다. 나는 많은 관련 질문을 읽었지만 아무도 내 문제에 대한 해결책을 가지고 있지 않다.Wordpress get_template_part가 작동하지 않습니다. loop-xxx.php 대신 404 페이지를 반환합니다.
다른 많은 테마에서 'get_template_part'를 사용하면 잘 작동합니다. 이번에 나는 무엇이 그 차이를 만들 었는지 모른다.
내 테마에는 등록 된 사용자 정의 게시 유형 이벤트이 있습니다. 이벤트의 게시물 URL은 example.com/event/wine-tasting입니다.
이 문제가된다
<?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) 여기
를 안감 대신 404 페이지를 반환example.com/event/ 내 archive.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; ?>
이 내가 '이벤트를'사용자 정의 포스트 유형을 등록하는 방법입니다 : 여기
내 루프 event.php입니다
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를 반환하지만 실제로는 example.com/event-category/all- 이벤트/* 등 ... 뇌가 단락되었습니다. –