但是我想和if else一起使用 -6ren">
gpt4 book ai didi

php - 在 wordpress 上一起使用 style.php 和 style.css

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

我今天刚刚完成了我的主题,并包含了带有 css.php 文件的主题设置页面,我可以在其中从面板更改网站颜色。

在我添加的标题中

<link rel='stylesheet' type='text/css' href="<?php bloginfo('template_directory'); ?>/css/style.php" />

但是我想和if else一起使用

例如如果安装了主题并且主题设置没有变化展示 <link rel='stylesheet' type='text/css' href="<?php bloginfo('template_directory'); ?>/css/style.css" /> CSS文件

但是当主题有变化时在主题设置页面去掉第一个css文件并显示

<link rel='stylesheet' type='text/css' href="<?php bloginfo('template_directory'); ?>/css/style.php" />

这可能吗?

最佳答案

您需要做的就是为主题设置保存操作添加一个标志。例如:

1: 在你的插件或主题 functions.php 中

add_action( 'optionsframework_after_validate', function(){ // this action is not real, you need to change it to your code
update_option( 'theme-settings-changed', 'changed' );
});

2:在你的主题头文件中

$change_check = get_option( 'theme-settings-changed' );
if ( $change_check == 'changed' ) {
?>
<link rel='stylesheet' type='text/css' href="<?php bloginfo('template_directory'); ?>/css/style.php" />
<?php
} else {
?>
<link rel='stylesheet' type='text/css' href="<?php bloginfo('template_directory'); ?>/css/style.css" />
<?php
}

此方法不能保证设置是否“实际”更改,因为它只是检查是否触发了保存按钮,而不管设置是否更改。但可以肯定的是,当用户更改值时保存按钮将被触发。如果这还不够,您可以为此目的添加一个检查逻辑,尽管这会很乏味。

关于php - 在 wordpress 上一起使用 style.php 和 style.css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25433347/

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