在wordpress主题开发中常常会需要用到多个文章分类管理及目录;
下面给大家分享一段添加post函数的方法
add_action(‘init’, ‘my_post_type_mytype’); function my_post_type_mytype() { register_post_type( ‘mytype’, array( ‘label’ => __(‘Mytype’, ‘My theme name’), ‘public’ => true, ‘show_ui’ => true, ‘show_in_nav_menus’ => false, ‘menu_position’ => 5, ‘rewrite’ => array( ‘slug’ => ‘services-view’, ‘with_front’ => FALSE, ), ‘supports’ => array( ‘title’, ‘thumbnail’, ‘editor’) ) ); } |
前台调用方法
//调用 $args = array( ‘post_type’ => ‘Mytype’, ‘numberposts’ => $num,//取到数量,其他参数可以查看 get_posts() 函数 ) $posts = get_posts($args); |
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END