Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php WordPress中具有自定义文章类型的单页层次结构_Php_Wordpress_Wordpress Theming_Custom Post Type - Fatal编程技术网

Php WordPress中具有自定义文章类型的单页层次结构

Php WordPress中具有自定义文章类型的单页层次结构,php,wordpress,wordpress-theming,custom-post-type,Php,Wordpress,Wordpress Theming,Custom Post Type,我有一个名为“城市”的自定义帖子类型。 对于这个自定义的职位类型,我将有N个城市相关 我正在尝试为这些页面创建文件,我认为这会起作用: single.php-通用的 single cities.php-列出城市 单一城市-{city slug}.php-为城市带来信息 当我尝试时: /cities-它显示的是single.php内容,而不是列表中的single cities内容 /cities/sao paulo-它正在工作。它显示了有关圣保罗的信息 测试: 如果我删除单城市-{city s

我有一个名为“城市”的自定义帖子类型。 对于这个自定义的职位类型,我将有N个城市相关

我正在尝试为这些页面创建文件,我认为这会起作用:

single.php-通用的

single cities.php-列出城市

单一城市-{city slug}.php-为城市带来信息


当我尝试时:

/cities-它显示的是single.php内容,而不是列表中的single cities内容

/cities/sao paulo-它正在工作。它显示了有关圣保罗的信息


测试:

如果我删除单城市-{city slug}.php,并尝试访问/cities/sao paulo,它将带来单城市.php


我在这个层次结构中做错了什么

注册自定义帖子类型的我的代码:

$city_args = array(
  'labels'              => $labels,
  'public'              => true,
  'has_archive'         => true,
  'publicly_queryable'  => true,
  'query_var'           => true,
  'capability_type'     => 'post',
  'hierarchical'        => false,
  'supports'             => array(
    'title'
  ),
  'exclude_from_search' => false,
  'menu_icon'           => 'dashicons-building'
);

register_post_type('cities', $city_args);
谢谢


更新

我想我误解了单页的概念。 php只是呈现一篇文章,而不是列出自定义文章类型的文章

通过阅读更多关于这一层次结构的内容,我试图了解我的城市列表结构,然后将城市信息纳入其中

也许我应该为城市创建一个页面,然后在这个页面(page cities.php)中创建代码来显示所有城市


点击每个城市,它应该进入single.php,是吗???

你会希望archive-cities.php列出所有城市,一个帖子中的单个城市。将此用作参考:

列出所有帖子的页面称为归档,它位于register\u post\u类型参数中声明的slug处

/城市-这是您的存档页面,因此它将调用archive cities.php

/城市/圣保罗-这是一个单一的职位。它将首先查找单城市-{city slug}.php,然后查找单城市.php


在大多数情况下,您只能使用single cities-{city slug}.php为特定城市创建唯一的模板文件。假设每个城市的帖子都使用相同的布局,您只需要single cities.php

将此代码添加到其他主题中,然后再试一次。