【问题标题】:Custom Post Type, the single-(post-type}.php自定义帖子类型,单(post-type}.php
【发布时间】:2016-12-27 09:12:55
【问题描述】:

所以我觉得我在做一些明显简单的事情,但不知道是什么! 我创建了我的自定义帖子类型 = Author 然后创建了 single-Author.php 来显示每个作者的信息但是当我打开每个作者的链接时 404.php

这里是自定义帖子类型作者

function p2p2_register_author(){
    $labels = array(
        'name'               => _x( 'همکاران', 'Author' ),
        'singular_name'      => _x('همکار','Author'),
        'add_new'            => _x( 'افزودن همکار', '' ),
        'add_new_item'       => __( 'افزودن همکاران جدید' ),
        'edit_item'          => __( 'ویرایش همکار' ),
        'new_item'           => __( 'همکار جدید' ),
        'all_items'          => __( 'همه همکاران' ),
        'search_items'       => __( 'جست و جو همکار' ),
        'not_found'          => __( 'همکاری یافت نشد' ),
        'not_found_in_trash' => __( 'همکار در زباله دان یافت نشد' ),
        'parent_item_colon'  => '',
        'menu_name'          => 'همکار'
    );

    register_post_type(
        'Author',
        array (
            'labels'             => $labels,
            'description'   => 'ذخیره اطلاعات مربوط به همکاران',
            'public'             => true,
            'publicly_queryable' => true,
            'show_ui'            => true,
            'show_in_menu'       => true,
            'query_var'          => true,
            'rewrite'            => array( 'slug' => 'author' ),
            'capability_type'    => 'post',
            'has_archive'        => true,
            'hierarchical'       => false,
            'menu_position'      => null,
            'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
        )
    );
}
        add_action('init', 'p2p2_register_author');
        flush_rewrite_rules();

我也有存档作者,它工作得很好,但单作者.php 不起作用。

任何帮助将不胜感激!

【问题讨论】:

    标签: php wordpress custom-post-type


    【解决方案1】:

    访问永久链接页面,然后刷新它。我的意思是点击Save Changes 按钮。希望你的问题能得到解决。如果不是,则将'has_archive' => true, 更改为'has_archive' => false,,然后再次点击永久链接页面上的Save Changes 按钮。您的问题将得到解决。

    【讨论】:

    • 这是有线的,我的一些帖子类型的帖子加载完美,但一些主题没有加载 single-Author.php,为什么?!!!
    • 在创建每个 archive-{post-type}.phpsingle-{post-type}.php 或此类其他模板后,需要刷新永久链接。原因 WordPress 需要被识别为层次结构的新成员。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    相关资源
    最近更新 更多