2013-03-22 2 views
1

일반적으로 온라인 또는 끝없는 실험을 통해 답변을 찾으려고 최선을 다합니다. 이번엔 정말 필사적이다. 나는 많은 관련 질문을 읽었지만 아무도 내 문제에 대한 해결책을 가지고 있지 않다.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') 
    ) 
); 

정말 감사드립니다. 나는 모든 것을 시도해 보았고 바보 같은 실수를 한 것은 나 였으면 좋겠다. 그러나 나는 지금까지 그것을 해결할 수 없었다. 미리 감사드립니다.

+1

이 문제는 정렬되었습니다. 기본적으로 어떻게 든 * example.com/event/*는 loop-event.php를 반환하지만 실제로는 example.com/event-category/all- 이벤트/* 등 ... 뇌가 단락되었습니다. –

답변

4

WordPress에 새로운 맞춤 게시물 유형을 추가 할 때 퍼머 링크를 플러시/새로 고침해야합니다. Settings > Permalinks으로 이동하여 변경 사항 저장 버튼 (두 번 클릭)을 클릭하십시오. 이렇게하면 문제가 해결됩니다.

+0

감사합니다. 나는 실제로 그것을 시도하고 효과가 있었지만 loop.php (* -event *가없는)을 만든 후에 만 ​​작동했습니다. 다른 포스트 타입을 가지고 있기 때문에 loop-event.php와 loop-lecture.php 등을 사용하고 싶습니다. 커스텀 포스트 타입 레지스터에 다시 쓰기를 시도합시다 ... 분 단위로 다시 ... –

+0

내 기쁨 연, 내가 도울 수있어서 기뻐. –

0

WordPress에서 생성 한 다시 쓰기 규칙을 플러시해야합니다.

아래 함수 만들기 : 사용자 정의 포스트 유형이 템플릿 사용중인 경우

function rewrite_flush() { 
    flush_rewrite_rules(); 
} 

을 :

add_action('after_switch_theme', 'rewrite_flush'); 

사용자 정의 포스트 유형이 플러그인을 사용중인 경우 :

register_activation_hook(__FILE__, 'rewrite_flush'); 

다른 방법은 @Sunny Johal의 답변입니다.

관련 문제