Php 类别段塞不工作
我正在开发一个报价网站,因为我希望每个类别都有不同的类别页面模板页面,我遵循wordpress的以下链接: 根据这一点,除了我原来的Php 类别段塞不工作,php,wordpress,Php,Wordpress,我正在开发一个报价网站,因为我希望每个类别都有不同的类别页面模板页面,我遵循wordpress的以下链接: 根据这一点,除了我原来的category.php文件之外,我让不同的类别流行起来author.php(也尝试了category-7.php bt不起作用),但不起作用。我还尝试了其他一些选择,如: 1) 在中尝试了此代码 functions.php function wpse_category_single_template( $single_template ) { globa
category.php
文件之外,我让不同的类别流行起来author.php
(也尝试了category-7.php bt不起作用),但不起作用。我还尝试了其他一些选择,如:
1) 在中尝试了此代码
functions.php
function wpse_category_single_template( $single_template ) {
global $post;
$all_cats = get_the_category();
if ( $all_cats[0]->cat_ID == '1' ) {
if ( file_exists(get_template_directory() . "/single-cat1.php") ) return get_template_directory() . "/single-cat1.php";
} elseif ( $all_cats[0]->cat_ID == '2' ) {
if ( file_exists(get_template_directory() . "/single-cat2.php") ) return get_template_directory() . "/single-cat2.php";
}
return $single_template;
}
add_filter( 'single_template', 'wpse_category_single_template' );
但是没有起作用
2) 改变了我的永久链接结构
3) 尝试将if…else
条件放入category.php
文件,如下所示:
<?php if (is_category('ID')) : ?>
// Code For Category with defined ID
<?php else : ?>
// Code for else
<?php endif; ?>
//具有已定义ID的类别的代码
//其他代码
但仍然没有进展
实际上wordpress找不到我的category slug.php
文件
怎么了?您的文件名应该是
category popular author.php
而不是category popular author.php
。你缺少dash
如果您的类别ID是7
,那么我猜您的文件位于错误的目录中。因为category-7.php
应该可以工作
抄本
模板层次结构指定WordPress将使用第一个模板
它在当前主题的目录中从
下列清单:
- category-slug.php
- category-ID.php
- category.php
- archive.php
- index.php
所以
category popular author.php
应该在wp content/themes/CURRENT\u THEME\u NAME/category popular author.php中。php
可能是打字错误,但你写的是“category popular author.php”而不是“category popular author.php”(注意缺少破折号)。是的,可能b category popolar author.php不应该在缺少破折号的bcz中工作。。但是我的分类id是对的,它是7,所以category-7.php应该可以工作!!!它与你在回答中提到的路径相同。刚刚在我的WP安装上测试了它。它可以和slug和ID配合使用。你的ID正确吗?打开类别编辑页面,在地址栏中搜索标签ID。虽然category popular author.php
应该可以完美地工作。你得到了什么输出?它是否显示默认的category.php
?是的…category.php页面正在运行imstead category-7.phpLets chat嘿,我没有足够的声誉来开始对话。。我们只能在这里解决这个问题吗?