php 使用模板注册新的自定义帖子类型

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 使用模板注册新的自定义帖子类型相关的知识,希望对你有一定的参考价值。


function create_posttype() {
 
    register_post_type( 'CUSTOM__POST__TYPE',
    // CPT Options
        array(
            'labels' => array(
                'name' => __( 'CUSTOM POST TYPE NAME' ),
                'singular_name' => __( 'CUSTOM__POST__TYPE' )
                
            ),
            'public' => true,
            'has_archive' => true,
            //if you want the post type to be absent from
            //site search
           // 'exclude_from_search' => true,
            'rewrite' => array('slug' => 'CUSTOM__POST__TYPE'),
        )
    );
    //if you have rules set, you'll need to use this
    //make sure you comment it back after running this once 
    //to improve performance
    //flush_rewrite_rules();
    
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );

	<?php include get_template_directory() . '/header.php'; ?>

<?php while ( have_posts() ) : the_post(); ?>
<!-- insert content and markup here -->
 <?php endwhile; ?>
 
 <?php include get_template_directory() . '/footer.php'; ?>
<?php
/**
* Template Name: Single Custom Post Type Template
* Description: This is for a single entry of a custom post type.
*/
?>
	
	<?php include get_template_directory() . '/header.php'; ?>

<?php while ( have_posts() ) : the_post(); ?>
<!-- insert content and markup here -->
 <?php endwhile; ?>
 
 <?php include get_template_directory() . '/footer.php'; ?>

以上是关于php 使用模板注册新的自定义帖子类型的主要内容,如果未能解决你的问题,请参考以下文章

自定义帖子类型的单个帖子模板覆盖

php 显示wordpress注册的自定义帖子类型列表

php MU插件|新的自定义帖子类型

php 将新的自定义帖子类型添加到Wordpress

如何从模板中的自定义帖子类型中仅提取一个类别?

通过自定义帖子类型中的字段分配模板的过滤器或操作挂钩