markdown WordPress中的自定义帖子类型和分类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown WordPress中的自定义帖子类型和分类相关的知识,希望对你有一定的参考价值。

This stuff needs to go in one of the php files. For Protect the Protest, Jason created a register_custom_types.php file.

I'm just going to put the contents of that file here, so I can copy and adapt it later as need be:

```php
<?php

// Register custom post types and taxonomies here.

function radicati_theme_init() {
  if(!taxonomy_exists('promotion_options')) {
    register_taxonomy('promotion_options', ['resource', 'post'], [
      'label' => __('Promotion Options'),
      'hierarchical' => true,
      'rewrite' => false,
      'public' => false,
      'show_ui' => true,
    ]);
  }

  if(!post_type_exists('resource')) {
    register_post_type('resource', [
      'label' => 'Resources',
      'labels' => [
        'name' => 'Resources',
        'singluar_name' => 'Resource',
      ],
      'public' => true,
      'show_in_menu' => true,
      'menu_position' => 5,
      'menu_icon' => 'dashicons-admin-tools',
      'supports' => [
        'title', 'editor', 'excerpt', 'page-attributes', 'thumbnail', 'custom-fields', 'author'
      ],
      'capability_type' => 'post',
      'taxonomies' => ['category', 'post_tag'],
    ]);
  }

  if(!term_exists('promoted_to_front_page', 'promotion_options')) {
    wp_insert_term('Promoted to Front Page', 'promotion_options', [
      'description' => 'Content that should displayed on the front page',
      'slug' => 'promoted_to_front_page',
    ]);

    // Add other default promotion options here.
  }

}

add_action('init', 'radicati_theme_init');


// Add Resources to category archive pages

function radicati__pre_get_posts($query) {
  if( (is_category() || is_tag()) && $query->is_archive() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
      'post', 'resource'
    ));
  }
  return $query;
}
add_filter('pre_get_posts', 'radicati__pre_get_posts');

```

以上是关于markdown WordPress中的自定义帖子类型和分类的主要内容,如果未能解决你的问题,请参考以下文章

根据 Wordpress 中的自定义字段值批量重写帖子 slug

WordPress中的自定义博客存档页面

用于显示距当前日期超过 8 个月的 WordPress 自定义帖子类型的自定义查询

Wordpress - 如何通过其分类过滤添加的自定义帖子?

填充不包括某些帖子类别的自定义 WordPress 帖子存档

wordpress中自定义帖子类型的分页