Wordpress滚动公告怎么做

   2025-07-25 admin00130

1、添加公告文章类型

首先,注册一个公告的文章类型,包括公告的新建,添加,编辑与删除。在functions.php的同级目录下新建一个gonggao.php,代码如下:

<?phpfunctionpost_type_bulletin(){register_post_type('bulletin',array('public'=>true,'publicly_queryable'=>true,'hierarchical'=>false,'labels'=>array('name'=>_x('公告','posttypegeneralname'),'singular_name'=>_x('公告','posttypesingularname'),'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');functioncreate_genre_taxonomy(){$labels=array('name'=>_x('公告分类','taxonomygeneralname'),'singular_name'=>_x('genre','taxonomysingularname'),'search_items'=>__('搜索分类'),'all_items'=>__('全部分类'),'parent_item'=>__('父级分类目录'),'parent_item_colon'=>__('父级分类目录:'),'edit_item'=>__('编辑公告分类'),'update_item'=>__('更新'),'add_new_item'=>__('添加新公告分类'),'new_item_name'=>__('NewGenreName'),);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);
 
举报收藏 0打赏 0评论 0
 
更多>同类资讯
推荐图文
推荐资讯
点击排行
网站首页  |  关于我们  |  联系方式  |  用户协议  |  隐私政策  |  版权声明  |  网站地图  |  RSS订阅  |  京ICP备2024057451号-2