在我们开发Wordpress主题的时候,我们会希望子分类继续使用父分类的页面模板,这样能大大减少我们的工作量。
那么WordPress子分类页面如何使用父页面模板呢?
这篇Wordpress教程详细为你解答。
//WordPress子分类页面使用父页面模板add_filter(\'category_template\', \'f_category_template\');function f_category_template($template){$category = get_queried_object();if($category->parent !=\'0\'){while($category->parent !=\'0\'){$category = get_category($category->parent);}}$templates = array(); if ( $category ) {$templates[] = \"category-{$category->slug}.php\";$templates[] = \"category-{$category->term_id}.php\";}$templates[] = \'category.php\';return locate_template( $templates );}
使用教程
将上面代码复制到主题的functions.php页面即可。
扫码关注wp主题君
精选优质免费WordPress主题模板,分享最新WordPress实用建站教程!
记住我们的网址:ztJun.com
文章链接:https://www.jitheme.com/2617.html
更新时间:2024年03月28日
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:service@jitheme.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读极(子)主题网络服务协议。