wordpress技术文档

wordpress的require 和 get_template_part get_template_directory_uri

日期:2020-12-02 阅读:670

子主题:

$dmwp_path = get_stylesheet_directory_uri ();
$dmwp_root = get_stylesheet_directory ();

-----------

父主题:

$dmwp_path = get_template_directory_uri();
$dmwp_root = get_template_directory();

-------------

<?php get_template_part( 'loop', 'index' ); ?>
will do a PHP require() for the first file that exists among these, in this priority:

wp-content/themes/twentytenchild/loop-index.php
wp-content/themes/twentyten/loop-index.php
wp-content/themes/twentytenchild/loop.php
wp-content/themes/twentyten/loop.php

从上面看的出来,后面的index并不是目录。而是文件名的补充。可有可无。

---------------

<link href="<?php echo get_template_directory_uri()?>/dmcssjs/owl.theme.css" rel="stylesheet" type="text/css" />


get_template_directory_uri  -- 这个只能是父主题。如果使用了子主题。则要用 get_stylesheet_directory_uri   


require get_theme_file_path().'/dminc/dmprolist_left.php';

get_theme_file_path不如用get_template_directory,因为get_theme_file_path是根据文件来的。如果文件在模板目录下,则一样。如果是模板的子目录下,就不一样。

------------

echo get_template_directory();
Returns an absolute server path (eg: /home/user/public_html/wp-content/themes/my_theme), not a URI.

In the case a child theme is being used, the absolute path to the parent theme directory will be returned. Use get_stylesheet_directory() to get the absolute path to the child theme directory.

To retrieve the URI of the stylesheet directory use get_stylesheet_directory_uri() instead.

Uses: get_theme_root() to retrieve the absolute path to the themes directory,
 get_template() to retrieve the directory name of the current theme.
Does not output a trailing slash --- 不带斜杠。

-------------