【问题标题】:Wordpress custom post type and taxonomy template fileWordpress 自定义帖子类型和分类模板文件
【发布时间】:2022-07-20 17:03:32
【问题描述】:

我创建了自定义帖子类型并注册了自定义分类法,我需要如何命名我的文件以实现自定义帖子类型类别模板?

function create_posttype_lankytinos_vietos() {
  
  register_post_type( 'lankytinos',
  // CPT Options
      array(
          'labels' => array(
              'name' => __( 'Lankytinos vietos' ),
              'singular_name' => __( 'Lankytina vieta' )
          ),
          'public' => true,
          'has_archive' => true,
          'rewrite' => array('slug' => 'lankytinos-vietos' , 'with_front' => true),
          'show_in_rest' => true,
          'taxonomies' => array('post_tag')

      )
  );
}


// Hooking up our function to theme setup
add_action( 'init', 'create_posttype_lankytinos_vietos' );

和自定义分类法


function tra_create_my_taxonomy() {

    register_taxonomy(
        'lankytina-kategorija',
        'lankytinos',
        array(
            'label' => __( 'Lankytinu vietu Kategorija' ),
            'rewrite' => array( 'slug' => 'lankytinos-vietos' ),
            'hierarchical' => true,
            'public' => true,
            'show_in_rest' => true
        )
    );
}
add_action( 'init', 'tra_create_my_taxonomy' );

我创建了一个名为 lietuvoje 的新类别,当我访问 lankytinos-vietos/lietuvoje 时,我得到了 index.php 文件,我需要如何命名模板文件来获得结果?

【问题讨论】:

    标签: php wordpress custom-post-type


    【解决方案1】:

    您需要在注册新的帖子类型后刷新永久链接。

    【讨论】:

    • 我这样做了,但仍然没有。
    猜你喜欢
    • 2013-03-17
    • 1970-01-01
    • 2013-08-03
    • 1970-01-01
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 2016-12-21
    • 1970-01-01
    相关资源
    最近更新 更多