将Wordpress主题模板文件移动到子目录 [英] Moving Wordpress Theme Template Files to Subdirectory

查看:23
本文介绍了将Wordpress主题模板文件移动到子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我正在创建的Wordpress主题中重新组织模板文件。现在,像single.phparchive.php这样的文件都在我的主题的根级别上。我想将它们移到它们自己的文件夹中--比如一个名为pages的文件夹。这样它看起来就像这样:

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

这可能吗?如果是,如何?

谢谢。

推荐答案

您可以使用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

这篇关于将Wordpress主题模板文件移动到子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆