我有以下代码为其注册自定义帖子类型和分类:
register_post_type( \'gs_business_listings\',
array(
\'labels\' => array(
\'name\' => __( \'Local Businesses\' ),
\'singular_name\' => __( \'Local Businesses\' )
),
\'public\' => true,
\'supports\' => array(\'title\', \'editor\', \'thumbnail\', \'revisions\'),
\'register_meta_box_cb\' => array($this,\'add_meta_boxes\'),
\'rewrite\' => array(\'slug\'=> \'%larger-region%/%regions%\')
)
);
register_taxonomy(
\'gs_business_region_harvey\',
\'gs_business_listings\',
array(
\'labels\' => array(
\'name\' => \'Harvey County\',
\'singular_name\' => \'Region\',
),
\'rewrite\' => array( \'slug\' => \'harvey-county\', \'hierarchical\' => true ),
\'hierarchical\' => true,
\'has_archive\' => true,
)
);
我希望访问
www.example.com/harvey-county
将显示使用自定义分类法的所有帖子的存档。但我找不到404。我怎么了?谢谢
注意:当前如果我访问www.example.com/harvey-county/newton
它显示newton
术语正确。
SO网友:Joshua Goossen
正如米洛所说,没有通用的分类学档案。但在我的情况下有一个是有道理的。下面是我模仿普通档案所做的:
我在Wordpress Admin name Harvey County中创建了一个空白页harvey-county
鼻涕虫然后我添加了一个page-harvey-county.php
模板文件到我的主题。我从我的archive.php
.我将循环部分调整为如下所示:
<?php
$taxonomy_terms = get_terms( \'gs_business_region_harvey\', array(
\'hide_empty\' => 0,
\'fields\' => \'ids\'
) );
$args = array(
\'post_type\' => \'gs_business_listings\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'gs_business_region_harvey\',
\'terms\' => $taxonomy_terms
),
),
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) : ?>
//header code
<?php
// Start the Loop.
$addressWrapper = array();
$addresses = array();
while ( $query->have_posts() ) : $query->the_post();
//Call get_template_part and such.
endwhile;
endif; ?>
这很管用,但有点让我烦恼,因为它不是很干,很容易复制
archive.php
.