douchuang1852 2016-01-08 18:26
浏览 36

如何在Wordpress中为特定的帖子类别创建自定义帖子模板

i need to create an custom template for childs of the a specific category. Is possible ?

  • 写回答

1条回答 默认 最新

  • douqin7086 2016-01-08 18:45
    关注

    You could add a conditional in your category.php or archive.php file for getting your custom template if url match the category or add a function in your functions.php theme. An example for the latest, where template_cat_c.php is your custom template:

    add_filter( 'template_include', 'template_cat' );
    
    function template_cat( $template ) {
      if ( is_subcategory_from($parent_id) ) {
        return 'template_cat_c.php';
      } else {
        return $template;
      }
    }
    

    Check the function there: https://wordpress.stackexchange.com/questions/89512/wordpress-function-like-is-category-for-subcategory-is-subcategory to make the is_subcategory_from($parent_id).

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度