第二个自定义帖子类型未在前端显示

时间:2019-07-09 07:57:30

标签: wordpress wordpress-plugin-creation

WP的后置类型代码正在运行,并显示在前端。但是,当复制它并将“合作”替换为“电影”时,它可以在管理端运行,但在前端返回404。

我删除了“电影”代码,并尝试了一些在网上找到的示例,但仍然存在相同的问题。它适用于1个帖子类型,但不超过1个。为什么?

“协作”代码转到正确的“ www.website.com/collaborations”,但第二个代码转到“ www.website.com/movies/movies/”。我在下面添加了“电影”代码。

协作代码

function create_movies()
{
    register_post_type('movies',
        array('labels' => array('name' => __('movies'),'singular_name' => __('Movies')),'public' => true,'has_archive' => false,'rewrite' => array('slug' => 'movies'))
    );
}
add_action('init','create_movies');

function cw_post_type_movies()
{
    $supports = array('title', 'editor', 'thumbnail', 'revisions');

    $labels = array(
        'name'          => _x('Movies', 'plural'),
        'singular_name' => _x('Movies', 'singular'),
        'menu_name'     => _x('Movies', 'admin menu'),
        'name_admin_bar'=> _x('Movies', 'admin bar'),
        'add_new'       => _x('Add New', 'add new'),
        'add_new_item'  => __('Add New Movies'),
        'new_item'      => __('New Movies'),
        'edit_item'     => __('Edit Movies'),
        'view_item'     => __('View Movies'),
        'all_items'     => __('View Movies'),
        'search_items'  => __('Search Movies'),
        'not_found'     => __('No Movies found.')
    );

    $args = array(
        'supports'      => $supports,
        'labels'        => $labels,
        'public'        => true,
        'query_var'     => true,
        'rewrite'       => array('slug' => 'movies'),
        'has_archive'   => true,
        'hierarchical'  => false
    );

    register_post_type('movies', $args);
}
add_action('init', 'cw_post_type_movies');

电影代码

def _send_gif(self, socket, chunk, packet_num, last_packet_num):
        main_record_len = 19
        static_gif_record_len = 11
        payload_len = len(chunk)
        gif_len = payload_len
        if packet_num == 0:
            gif_len += static_gif_record_len
        packet_len = main_record_len + gif_len
        buf = bytearray()
        buf.extend(binascii.unhexlify('ffffffff'))
        buf.extend(struct.pack("<H", packet_len))
        buf.extend(struct.pack("<H", 0))
        to_checksum = bytearray()
        to_checksum.append(0x68)
        to_checksum.append(0x32)
        to_checksum.append(0x01)
        to_checksum.append(0x7b)
        to_checksum.append(0x01)
        to_checksum.extend(struct.pack("<h", gif_len))
        to_checksum.append(packet_num)
        to_checksum.append(last_packet_num)
        if packet_num == 0:
            to_checksum.append(0x03)
            to_checksum.append(0x00)
            to_checksum.append(0x00)
            to_checksum.append(0x00)
            to_checksum.extend(struct.pack(">H", 0x00))
            to_checksum.append(0x01)
            to_checksum.extend(struct.pack(">H", 0x00))
            to_checksum.extend(struct.pack(">H", 0x00))
        to_checksum.extend(chunk)
        buf.extend(to_checksum)
        checksum = 0
        for c in to_checksum:
            checksum += c
            if checksum > 0xffff:
                checksum -= 0xffff
        packed_checksum = struct.pack("<H", checksum)
        buf.extend(packed_checksum)
        socket.sendall(buf)

1 个答案:

答案 0 :(得分:0)

您为什么两次做相同的帖子?

也许我错了,但我认为您只需要第二个功能。

1.) function cw_post_type_movies() 
2.) function cw_post_type_collaborations()

对于电影,只需使用:

function cw_post_type_movies(){
$supports = array('title', 'editor', 'thumbnail', 'revisions');

$labels = array(
    'name'          => _x('Movies', 'plural'),
    'singular_name' => _x('Movies', 'singular'),
    'menu_name'     => _x('Movies', 'admin menu'),
    'name_admin_bar'=> _x('Movies', 'admin bar'),
    'add_new'       => _x('Add New', 'add new'),
    'add_new_item'  => __('Add New Movies'),
    'new_item'      => __('New Movies'),
    'edit_item'     => __('Edit Movies'),
    'view_item'     => __('View Movies'),
    'all_items'     => __('View Movies'),
    'search_items'  => __('Search Movies'),
    'not_found'     => __('No Movies found.')
);

$args = array(
    'supports'      => $supports,
    'labels'        => $labels,
    'public'        => true,
    'query_var'     => true,
    'rewrite'       => array('slug' => 'movies'),
    'has_archive'   => true,
    'hierarchical'  => false
);

register_post_type('movies', $args);
}
add_action('init', 'cw_post_type_movies');

对于协作,请使用:

function cw_post_type_collaborations(){
$supports = array('title', 'editor', 'thumbnail', 'revisions');

$labels = array(
    'name'          => _x('Collaborations', 'plural'),
    'singular_name' => _x('Collaborations', 'singular'),
    'menu_name'     => _x('Collaborations', 'admin menu'),
    'name_admin_bar'=> _x('Collaborations', 'admin bar'),
    'add_new'       => _x('Add New', 'add new'),
    'add_new_item'  => __('Add New Collaborations'),
    'new_item'      => __('New Collaborations'),
    'edit_item'     => __('Edit Collaborations'),
    'view_item'     => __('View Collaborations'),
    'all_items'     => __('View Collaborations'),
    'search_items'  => __('Search Collaborations'),
    'not_found'     => __('No Collaborations found.')
);

$args = array(
    'supports'      => $supports,
    'labels'        => $labels,
    'public'        => true,
    'query_var'     => true,
    'rewrite'       => array('slug' => 'collaborations'),
    'has_archive'   => true,
    'hierarchical'  => false
);

register_post_type('collaborations', $args);
}
add_action('init', 'cw_post_type_collaborations'); 

创建两种自定义帖子类型后,请转到:

您的域/ wp-admin

设置>永久链接>保存更改

=>永久链接已刷新