自定义类别的布局

时间:2016-06-15 20:17:23

标签: wordpress

我在wordpress中有一个项目

在我的项目中有两种自定义帖子类型(视频 - 照片)

每种类型都有自定义类别

我怎样才能为每个类别编写代码,每个类别都有不同的样式

我要添加的文件是什么?

每个人的代码是什么?

这是我在functions.php中的代码

<?php
// Rigester Custom Post Video
add_action( 'init', 'codex_video_init' );
/**
 * Register a video post type.
 *
 * @link http://codex.wordpress.org/Function_Reference/register_post_type
 */
function codex_video_init() {
    $labels = array(
        'name'               => _x( 'Video', 'post type general name', 'your-plugin-textdomain' ),
        'singular_name'      => _x( 'Video', 'post type singular name', 'your-plugin-textdomain' ),
        'menu_name'          => _x( 'Video', 'admin menu', 'your-plugin-textdomain' ),
        'name_admin_bar'     => _x( 'Video', 'add new on admin bar', 'your-plugin-textdomain' ),
        'add_new'            => _x( 'Add New', 'pdf', 'your-plugin-textdomain' ),
        'add_new_item'       => __( 'Add New Video', 'your-plugin-textdomain' ),
        'new_item'           => __( 'New Video', 'your-plugin-textdomain' ),
        'edit_item'          => __( 'Edit Video', 'your-plugin-textdomain' ),
        'view_item'          => __( 'View Video', 'your-plugin-textdomain' ),
        'all_items'          => __( 'All Videos', 'your-plugin-textdomain' ),
        'search_items'       => __( 'Search Videos', 'your-plugin-textdomain' ),
        'parent_item_colon'  => __( 'Parent Video:', 'your-plugin-textdomain' ),
        'not_found'          => __( 'No Video found.', 'your-plugin-textdomain' ),
        'not_found_in_trash' => __( 'No Video found in Trash.', 'your-plugin-textdomain' )
    );

    $args = array(
        'labels'             => $labels,
                'description'        => __( 'Description.', 'your-plugin-textdomain' ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'video' ),
        'capability_type'    => 'post',
        'taxonomies'         => array( 'category' ),
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    );

    register_post_type( 'video', $args );
}


// Rigester Custom Post Photo
add_action( 'init', 'codex_photo_init' );
/**
 * Register a photo post type.
 *
 * @link http://codex.wordpress.org/Function_Reference/register_post_type
 */
function codex_photo_init() {
    $labels = array(
        'name'               => _x( 'Photo', 'post type general name', 'your-plugin-textdomain' ),
        'singular_name'      => _x( 'Photo', 'post type singular name', 'your-plugin-textdomain' ),
        'menu_name'          => _x( 'Photo', 'admin menu', 'your-plugin-textdomain' ),
        'name_admin_bar'     => _x( 'Photo', 'add new on admin bar', 'your-plugin-textdomain' ),
        'add_new'            => _x( 'Add New', 'photo', 'your-plugin-textdomain' ),
        'add_new_item'       => __( 'Add New Photo', 'your-plugin-textdomain' ),
        'new_item'           => __( 'New Photo', 'your-plugin-textdomain' ),
        'edit_item'          => __( 'Edit Photo', 'your-plugin-textdomain' ),
        'view_item'          => __( 'View Photo', 'your-plugin-textdomain' ),
        'all_items'          => __( 'All Photos', 'your-plugin-textdomain' ),
        'search_items'       => __( 'Search Photos', 'your-plugin-textdomain' ),
        'parent_item_colon'  => __( 'Parent Photo:', 'your-plugin-textdomain' ),
        'not_found'          => __( 'No Photo found.', 'your-plugin-textdomain' ),
        'not_found_in_trash' => __( 'No Photo found in Trash.', 'your-plugin-textdomain' )
    );

    $args = array(
        'labels'             => $labels,
                'description'        => __( 'Description.', 'your-plugin-textdomain' ),
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'photo' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
    );

    register_post_type( 'photo', $args );
}
?>

1 个答案:

答案 0 :(得分:0)

简单地说,复制你的主题&#34; category.php&#34;,重命名&#34; category-CATID.php&#34;并上传主题文件夹。

将CATID替换为您的类别ID,然后为您的猫编辑。