### [WordPress滚动公告怎么做](https://www.prosaas.cn/article/2823) **Published:** 2019-07-12T03:41:41 **Author:** 5201314 **Excerpt:** 1、添加公告文章类型首先,注册一个公告的文章类型,包括公告的新建,添加,编辑与删除。在functions.ph…  **1、添加公告文章类型** 首先,注册一个公告的文章类型,包括公告的新建,添加,编辑与删除。在functions.php的同级目录下新建一个 gonggao.php ,代码如下: true, 'publicly\_queryable' => true, 'hierarchical' => false, 'labels'=>array( 'name' => \_x('公告', 'post type general name'), 'singular\_name' => \_x('公告', 'post type singular name'), 'add\_new' => \_x('添加新公告', '公告'), 'add\_new\_item' => \_\_('添加新公告'), 'edit\_item' => \_\_('编辑公告'), 'new\_item' => \_\_('新的公告'), 'view\_item' => \_\_('预览公告'), 'search\_items' => \_\_('搜索公告'), 'not\_found' => \_\_('您还没有发布公告'), 'not\_found\_in\_trash' => \_\_('回收站中没有公告'), 'parent\_item\_colon' => '' ), 'show\_ui' => true, 'menu\_position'=>5, 'supports' => array( 'title', 'author', 'excerpt', 'thumbnail', 'trackbacks', 'editor', 'comments', 'custom-fields', 'revisions' ) , 'show\_in\_nav\_menus' => true , 'menu\_icon' => 'dashicons-megaphone', 'taxonomies' => array( 'menutype', 'post\_tag') ) );}add\_action('init', 'post\_type\_bulletin'); function create\_genre\_taxonomy() { $labels = array( 'name' => \_x( '公告分类', 'taxonomy general name' ), 'singular\_name' => \_x( 'genre', 'taxonomy singular name' ), 'search\_items' => \_\_( '搜索分类' ), 'all\_items' => \_\_( '全部分类' ), 'parent\_item' => \_\_( '父级分类目录' ), 'parent\_item\_colon' => \_\_( '父级分类目录:' ), 'edit\_item' => \_\_( '编辑公告分类' ), 'update\_item' => \_\_( '更新' ), 'add\_new\_item' => \_\_( '添加新公告分类' ), 'new\_item\_name' => \_\_( 'New Genre Name' ), ); register\_taxonomy('genre',array('bulletin'), array( 'hierarchical' => true, 'labels' => $labels, 'show\_ui' => true, 'query\_var' => true, 'rewrite' => array( 'slug' => 'genre' ), ));}add\_action( 'init', 'create\_genre\_taxonomy', 0 ); 在functions.php中引用该公告的gonggao.php文件,在functions.php的底部加上如下代码: include ("gonggao.php"); 之后,再登录到wordpress网站的后台,就可以看到在文章的下面多了一个公告标签。 上述代码中的 'menu\_icon' => 'dashicons-megaphone', 就是我们设定的 Dashicons 图标,效果如下图。如果去掉这行的话,图标默认和文章的图标一样。 **2\. 添加公告样式** 将下面的公告内容代码放在 index.php 自己想要显示的位置: