【问题标题】:Moving Wordpress Theme Template Files to Subdirectory将 Wordpress 主题模板文件移动到子目录
【发布时间】:2020-06-20 16:34:33
【问题描述】:

我想在我正在创建的 Wordpress 主题中重组模板文件。现在,single.php 和 archive.php 等文件位于我主题的根级别。我想将它们移动到他们自己的文件夹中——比如一个名为pages 的文件夹。所以它看起来像这样:

mytheme 
  -- pages
      -- archive.php
      -- single.php
  -- functions.php
  -- index.php
  -- style.css

这可能吗?如果有,怎么做?

谢谢。

【问题讨论】:

    标签: wordpress wordpress-theming


    【解决方案1】:

    您可以将single_template 过滤器和{$type}_template 过滤器用于存档、类别等。

    我觉得这样的东西就是你要找的东西:

    function get_new_single_template( $single_template ) {
      global $post;
        $single_template = get_stylesheet_directory() . '/pages/single.php';
      return $single_template;
    }
    add_filter( 'single_template', 'get_new_single_template' );
    
    function get_new_archive_template( $archive_template ) {
      global $post;
        $archive_template = get_stylesheet_directory() . '/pages/archive.php';
      return $archive_template;
    }
    add_filter( 'archive_template', 'get_new_archive_template' );
    

    发送给您的functions.php

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-01
      • 1970-01-01
      相关资源
      最近更新 更多