【问题标题】:How do I add an Excerpt box to custom post types in functions?如何将摘录框添加到函数中的自定义帖子类型?
【发布时间】:2014-06-25 04:43:57
【问题描述】:

我只想要标准的摘录框 - 而不是我自己创建的元框,添加到自定义帖子中。该框显示在帖子中,但不在自定义帖子中。我已经尝试过这两种较旧的解决方案,但都没有奏效(可能是 WP 3.9 的问题):

自定义帖子类型名称为“独家新闻”

我将此添加到register_post_type_scoop() $labels = array

'supports' => array('title','thumbnail','excerpt')

但它没有用 - 这也没有:

add_post_type_support('Scoop', 'title');
add_post_type_support('Scoop', array('title', 'thumbnail', 'excerpt') );

【问题讨论】:

  • 我通过这个插件找到了答案:wordpress.org/plugins/rich-text-excerpts/installation,函数中的这段代码将摘录添加到命名的自定义帖子类型:add_action('init', 'my_custom_init'); function my_custom_init() { add_post_type_support( 'scoop', 'excerpt' ); } 我知道这很简单——只是找不到。

标签: custom-post-type wordpress-3.9


【解决方案1】:

将索引值excerpt 添加到supports 对象。下面的例子是:

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'),
    )
  );
}

【讨论】:

    猜你喜欢
    • 2018-01-08
    • 2011-11-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-29
    • 2012-07-29
    • 2013-08-04
    • 1970-01-01
    相关资源
    最近更新 更多