반응형
사용자 지정 게시물 유형에 대한 읽기 설정에 정적 페이지 추가
사용자 지정 게시물 유형을 만들었고 사용자가 보관 페이지에 대한 정적 페이지를 선택할 수 있도록 하고 싶습니다.예를 들어, [게시] 페이지 아래에 있습니다.Projects 페이지를 추가합니다. [ Dropout ]
읽기 설정 페이지에 다른 정적 페이지 옵션을 추가하는 방법이 있습니까?그것을 수정할 수 있는 기존의 후크가 있습니까?
또한 선택한 페이지를 페이지에 이렇게 표시하는 방법이 있습니까?
업데이트:
을 살피는 것/wp/wp-admin/includes/template.php:1768
/**
* Filters the default post display states used in the posts list table.
*
* @since 2.8.0
* @since 3.6.0 Added the `$post` parameter.
*
* @param array $post_states An array of post display states.
* @param WP_Post $post The current post object.
*/
$post_states = apply_filters( 'display_post_states', $post_states, $post );
if ( ! empty($post_states) ) {
$state_count = count($post_states);
$i = 0;
echo ' — ';
foreach ( $post_states as $state ) {
++$i;
( $i == $state_count ) ? $sep = '' : $sep = ', ';
echo "<span class='post-state'>$state$sep</span>";
}
}
post_state에 갈고리가 있는 것 같은데 어떻게 설정합니까?
그리고./wp-admin/options-reading.php:83
실제로 파일을 수정하지 않고 Reading 설정을 수정할 수 있는 방법이 있습니까?
읽기 설정 페이지에 다른 정적 페이지 옵션을 추가하는 방법이 있습니까?
네.
코드:
/**
* Adds a custom field: "Projects page"; on the "Settings > Reading" page.
*/
add_action( 'admin_init', function () {
$id = 'page_for_projects';
// add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() )
add_settings_field( $id, 'Projects page:', 'settings_field_page_for_projects', 'reading', 'default', array(
'label_for' => 'field-' . $id, // A unique ID for the field. Optional.
'class' => 'row-' . $id, // A unique class for the TR. Optional.
) );
} );
/**
* Renders the custom "Projects page" field.
*
* @param array $args
*/
function settings_field_page_for_projects( $args ) {
$id = 'page_for_projects';
wp_dropdown_pages( array(
'name' => $id,
'show_option_none' => '— Select —',
'option_none_value' => '0',
'selected' => get_option( $id ),
) );
}
/**
* Adds page_for_projects to the white-listed options, which are automatically
* updated by WordPress.
*
* @param array $options
*/
add_filter( 'whitelist_options', function ( $options ) {
$options['reading'][] = 'page_for_projects';
return $options;
} );
미리보기:
또한 선택한 페이지를 페이지에 이렇게 표시하는 방법이 있습니까?
네.
코드:
/**
* Filters the post states on the "Pages" edit page. Displays "Projects Page"
* after the post/page title, if the current page is the Projects static page.
*
* @param array $states
* @param WP_Post $post
*/
add_filter( 'display_post_states', function ( $states, $post ) {
if ( intval( get_option( 'page_for_projects' ) ) === $post->ID ) {
$states['page_for_projects'] = __( 'Projects Page' );
}
return $states;
}, 10, 2 );
미리보기:
필요하거나 필요한 경우, JavaScript/jQuery를 사용하여 "프로젝트 페이지" 필드를 "홈페이지 표시" 열의 "게시물 페이지" 아래로 이동할 수 있습니다.
언급URL : https://stackoverflow.com/questions/48724545/add-static-page-to-reading-settings-for-custom-post-type
반응형
'programing' 카테고리의 다른 글
파워셸 출력 열폭 (0) | 2023.10.29 |
---|---|
도커를 루트가 아닌 것으로 복사하려면 어떻게 해야 합니까? (0) | 2023.10.29 |
Oracle SQL의 변수를 통한 시간 간격 전달 (0) | 2023.10.29 |
SQL 다른 테이블을 기준으로 행 삭제 (0) | 2023.10.29 |
MySQL에서 부여 보기 (0) | 2023.10.24 |