在wordpress主题开发中常常会需要用到多个文章分类管理及目录;
下面给大家分享一段添加post函数的方法
area data-settings="dblclick" readonly >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') ) );} area>16171819202122add_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')) );}
前台调用方法
area data-settings="dblclick" readonly >//调用$args = array( 'post_type' => 'Mytype', 'numberposts' => $num,//取到数量,其他参数可以查看 get_posts() 函数 )$posts = get_posts($args); area>12345678//调用$args = array('post_type' => 'Mytype','numberposts' => $num,//取到数量,其他参数可以查看 get_posts() 函数)$posts = get_posts($args);