gpt4 book ai didi

php - 我如何找出我的 CSS 不显示的原因?

转载 作者:行者123 更新时间:2023-11-28 00:09:15 28 4
gpt4 key购买 nike

我正在制作一个网站,任何以前没有使用过 HTML 的用户都可以对其进行更改,所以我选择了 Wordpress。我查找了为 22 十二主题制作子主题的方法并尝试自定义它,但由于某种原因 CSS 不会显示。

我已经尝试多次更改 style.css 和 functions.php 文件,例如添加包含在教程中的 CSS。没用。然后我添加了自己的 CSS,但也没有用。我也将其留空并使用 wp 上的“自定义附加 CSS”工具添加了附加 CSS,或者转到主题编辑器并在其中添加 CSS。我还多次更改了 functions.php 中的内容并删除了该文件,但它不起作用。我查看了为什么会发生这种情况并尝试了一些方法,但它们没有帮助。

这是 style.css 文件:

/*  
Theme Name: Twenty Twelve Child
Description: Twenty Twelve Child Theme
Template: twentytwelve
*/
@import url("../twentytwelve/style.css");

[ my custom css ]

和 functions.php:

<?php
function theme_enqueue_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
}
add_action( 'wp_enqueue_scripts', 'theme_enqueue_styles' );
?>

我尝试了这些和许多其他方法,但都没有用。任何类型的帮助或提示将不胜感激。

更新:我有一些其他文件,如 footer.php 或 header.php,当我从文件夹中删除它们时,CSS 会出现。这些文件可能有问题吗?

最佳答案

尝试将其用于 functions.php

 <?php
function twentytwelve_child_theme_child_theme_enqueue_styles() {
$parent_style = 'twentytwelve_child_theme_parent_style';
$parent_base_dir = 'twentytwelve';

wp_enqueue_style( $parent_style,
get_template_directory_uri() . '/style.css',
array(),
wp_get_theme( $parent_base_dir ) ? wp_get_theme( $parent_base_dir )->get('Version') : ''
);

wp_enqueue_style( $parent_style . '_child_style',
get_stylesheet_directory_uri() . '/style.css',
array( $parent_style ),
wp_get_theme()->get('Version')
);
}

add_action( 'wp_enqueue_scripts', 'twentytwelve_child_theme_child_theme_enqueue_styles' );

对于 style.css,只使用这个(没有@import):

/*
Theme Name: Twenty Twelve Child
Description: Twenty Twelve Child Theme
Template: twentytwelve
Version: 1.0.0
*/

还没有测试,但应该可以:)

关于php - 我如何找出我的 CSS 不显示的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55497576/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com