首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress -访问自定义的post类型的帖子

Wordpress -访问自定义的post类型的帖子
EN

Stack Overflow用户
提问于 2016-01-21 12:47:10
回答 1查看 39关注 0票数 1

我已经做了一个自定义的post类型,并做了一个功能,所以它显示在主页上。这是我的密码:

代码语言:javascript
复制
function create_recipe_post_type() {
    $recipe_labels = array(
        'name'              => 'Recipes',
        'singular_name'     => 'Recipe',
        'menu_name'         => 'Recipes',
        'name_admin_bar'    => 'Recipe'
    );

    register_post_type( 'recipes',
        $args = array(
            'labels' => $recipe_labels,
            'public' => true,
            'supports' => array(
                'title',
                'editor',
                'post-formats',
                'author',
                'thumbnail',
                'excerpt',
                'comments'
            ),
            'has_archive' => true,
            'menu_icon' => 'dashicons-carrot',
            'query_var' => 'recipes'
        )
    );
}
add_action( 'init', 'create_recipe_post_type' );

add_post_type_support( 'recipe_post_type', 'post-formats' );

// Add custom post type posts to main page
add_action( 'pre_get_posts', 'add_recipe_to_main_page' );

function add_recipe_to_main_page( $query ) {
    if ( is_home() && $query->is_main_query() )
        $query->set( 'post_type', array( 'post', 'recipes' ) );
    return $query;
}

在文档中,我发现我可以使用

单-{post型}.php

但是如果我创建了一个名为

single-recipes.php

我仍然得到了“未找到的页面”错误。有办法解决这个问题吗?还是我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-21 12:50:03

有时,您必须进入permalink设置,并将它们从默认更改为自定义,然后保存,然后返回并再次将它们更改为默认设置。当我有这个问题的时候我很适合我

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34924264

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档