WordPress 사용자 지정 게시 유형 아카이브-.php가 작동 하지 않습니다.
WordPress를 처음 접한 저는 커스텀 투고 타입의 아카이브 페이지를 작성하려고 했습니다만, 링크를 클릭하면localhost/websitename/wordpress/archive-event.php난 404점이야.투고 타입을 등록하기 위한 코드는 다음과 같습니다.
add_action('init', 'event_register');
function event_register() {
$labels = array(
'name' => _x('Events', 'post type general name'),
'singular_name' => _x('Event', 'post type singular name'),
'add_new' => _x('Add New', 'event'),
'add_new_item' => __('Add New Event'),
'edit_item' => __('Edit Event'),
'new_item' => __('New Event'),
'view_item' => __('View Event'),
'search_items' => __('Search Events'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'event'),
'has_archive' => 'event',
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','thumbnail'),
);
register_post_type( 'event' , $args );
}
나는 시도했다.rewrite => true,has_archive => true, 개서 룰을 플래시 해, 투고 타입의 분류법을 등록하는 것까지 합니다. single-event.php정상적으로 동작합니다.그럼 어쩌라는 거야?
커스텀 투고 타입의 아카이브 페이지에는, 2개만 필요합니다.
1)has_archive그래야 한다true
2) 코드 업데이트 후 permalink 캐시를 한 번 플러시해야 합니다.
기능들.php
function my_custom_posts() {
$labels = array(
'name' => _x( 'Events', 'post type general name' ),
'singular_name' => _x( 'Event', 'post type singular name' ),
'add_new' => _x( 'Add New', 'event' ),
'add_new_item' => __( 'Add New Event' ),
'edit_item' => __( 'Edit Event' ),
'new_item' => __( 'New Event' ),
'all_items' => __( 'All Events' ),
'view_item' => __( 'View Event' ),
'search_items' => __( 'Search Events' ),
'not_found' => __( 'No events found' ),
'not_found_in_trash' => __( 'No events found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Events'
);
$args = array(
'labels' => $labels,
'description' => 'Holds our events and event specific data',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title' ),
'has_archive' => true, // only this is required to enable archive page else 404 error will occur
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'events', 'with_front' => true),
'capability_type' => 'post',
'hierarchical' => false,
);
register_post_type( 'event', $args );
//flush_rewrite_rules();
}
add_action( 'init', 'my_custom_posts' );
체납archive.php동작하지만 기본 파일을 덮어쓰려면 적절한 아카이브 템플릿을 사용해야 합니다.archive-<custom_post_slug>.php,예.
archive-events.php
또, 투고 타입을 등록하고 있는 경우는, 퍼머링크 캐시를 플래시 할 필요가 있습니다.이를 수행하려면 Wordpress admin으로 permalink 구조를 변경합니다.
아카이브 페이지https://domain/post_slug/에 액세스 할 수 있게 되었습니다.
주의: 선택하신 경우Numericpermalink structure url은 https://domain/domain/domain/post_dump
이것이 당신의 질문에 대답할지는 모르겠지만, 당신의 영구 링크 구조를 리셋했습니까?
커스텀 투고 타입을 추가한 경우 Permalinks 페이지로 이동하여 Save를 눌러야 합니다.
도움이 됐으면 좋겠네요!
URL 예제에서는 실제 템플릿 파일 이름 자체에 액세스하려고 시도하는 것처럼 보입니다.
하지만 만약 당신이 그 총알을eventlocalhost/wordpress/event를 방문하기만 하면 됩니다.
기본적으로 "Has Archive" 플래그가 False로 설정되어 있는 CPT UI 플러그인을 사용하고 있었습니다.이것은 다음에서 변경할 수 있습니다.
"Edit Post Type" tab > "Settings" > "Has Archive"
대신 True로 설정하고 Permalinks를 플러시하는 것을 잊지 마십시오(Permalinks 페이지에서 Save 클릭).
Permalink 구조에 문제가 있습니다.= > Permalink 설정을 "Day and name" 또는 "Month and name" 또는 "Post name"으로 변경하여 문제가 해결되었습니다.
언급URL : https://stackoverflow.com/questions/16968604/wordpress-custom-post-type-archive-post-type-php-not-working
'programing' 카테고리의 다른 글
| ng-animate : 모델 변경 시 애니메이션 (0) | 2023.03.15 |
|---|---|
| 속성을 기반으로 WooCommerce 제품 쿼리 (0) | 2023.03.15 |
| 워드프레스에서 mysql 트랜잭션을 사용하는 방법은 무엇입니까? (0) | 2023.03.15 |
| woocommerce 제품에 콘텐츠가 없을 때 사용자 지정 탭 숨기기 (0) | 2023.03.15 |
| TypeScript 컴파일러 Array.protype을 확인하는 방법.필터가 어레이에서 특정 유형을 제거합니까? (0) | 2023.03.15 |