2017-08-01 58 views
0

我在WordPress中創建了一個自定義帖子類型,我如何添加自定義摘錄在此添加一個字段。自定義帖子類型保存在相同的wp_posts表中。和「添加」選項顯示所有字段。但是現在我想在此添加自定義摘錄字段。我有任何WordPress功能添加摘錄。任何人都可以幫忙如何在wordpress中添加自定義文章類型的摘錄?

回答

1

如何在WordPress中添加自定義帖子類型的摘錄?

實施例無1:

<?php 
/** 
* Enables the Excerpt meta box in post type edit screen. 
*/ 
function wpcodex_add_excerpt_support_for_post() { 
    add_post_type_support('your post type slug name here', 'excerpt'); 
} 
add_action('init', 'wpcodex_add_excerpt_support_for_post'); 
?> 

詳情這裏:https://codex.wordpress.org/Function_Reference/add_post_type_support

實施例沒有2:

<?php 
add_action('init', 'create_testimonial_posttype'); 
function create_testimonial_posttype(){ 
    register_post_type('testimonials', 
    array(
     'labels' => array(
     'name' => __('Testimonials'), 
     'singular_name' => __('Testimonial') 
    ), 
     'public' => true, 
     'has_archive' => true, 
     'rewrite' => array('slug' => 'clients'), 
     'supports' => array('title','thumbnail','editor','page-attributes','excerpt'), 
    ) 
); 
} 
?> 
1

的支持字段更改爲這個 '支持'=>數組( 'title','editor','author','thumbnail','excerpt','comments'));

0

我希望你已經通過在主題function.php文件中添加函數register_post_type()來創建自定義文章類型。如果是的話,你只需用'支持'來更新你的代碼。然後轉到屏幕選項並點擊'摘錄'。

$args = array(
    'supports'   => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments') 
); 

register_post_type('book', $args); 

或者你也可以添加以下代碼

add_action('init', 'my_add_excerpts_to_pages'); 
function my_add_excerpts_to_pages() { 
    add_post_type_support('page', 'excerpt'); //change page with your post type slug. 
} 
0

在屏幕上方有即屏幕選項選擇添加exceprt同時加入職。選擇專家,並將exceprt字段自動添加到添加帖子頁面。

相關問題