我有自定义帖子类型“产品”及其分类“产品类别”。
我需要这样的网址:
现在,第三个 URL 看起来像 https://example.com/product/product-page/ 如果我在自定义帖子类型创建功能中设置
'rewrite' => array('slug' => 'products', 'hierarchical' => true, 'with_front' => false )
我在 https://example.com/products/ 上获得默认的 WP archive.php 模板(而不是带有税务查询的页面)。
我该如何修复它? 谢谢!
在主题文件夹中创建一个名为
archive-{posttype}
的文件,您可以为自定义帖子类型创建自定义存档页面。
如果您的帖子类型有 products
,那么它就是 archive-products.php
。在此 php 文件内,您可以输入税务查询。该文件将在访问“url.com/products”时使用
请注意,您在注册帖子类型时需要将
has_archive
设置为 true
。
如果您不想在主题文件夹中拥有单独的存档文件,您可以在
archive.php
文件中使用函数:https://developer.wordpress.org/reference/functions/is_post_type_archive/