WordPress :带有 HTML 和包含的 If 语句
WordPress : If Statement with HTML and Includes
我想在我的 wordpress header.php 文件中包含一个包含 php 的不同内联 <style>
标签,具体取决于它是我的博客还是页面。
简单来说,我希望我的博客在 <head>
<style type="text/css">
<?php include '../css/1.css.php';?>
</style>
并且我希望我的页面在 <head>
中包含另一个页面
<style type="text/css">
<?php include '../css/2.css.php';?>
</style>
我找到了这个片段并且博客和页面之间的区别有效,问题是包含行
<?php
if(is_page()){
echo 'Foo';
include ('../css/above-the-fold-contact.css.php');
echo 'Example: one';
}
else{
echo 'Foo something else';
include ('../css/above-the-fold-blog.css.php');
echo 'Example: two';
}
?>
它确实在正确的页面中注入了正确的文件,但我需要将 include 包裹在 <style>
标签周围,不这样做会导致文件的内容以纯文本形式注入。我怎么做?语法是什么?非常感谢任何帮助,非常感谢!
<?php
echo '<style type="text/css">';
if( is_page() ) { include '../css/above-the-fold-contact.css.php'; }
else { include '../css/above-the-fold-blog.css.php'; }
echo '</style>';
EDIT :简单提一下 - 如果你的 CSS 不是动态生成的,那么有更好的方法来做到这一点(比如 wp_enqueue_style
,例如 )
我想在我的 wordpress header.php 文件中包含一个包含 php 的不同内联 <style>
标签,具体取决于它是我的博客还是页面。
简单来说,我希望我的博客在 <head>
<style type="text/css">
<?php include '../css/1.css.php';?>
</style>
并且我希望我的页面在 <head>
<style type="text/css">
<?php include '../css/2.css.php';?>
</style>
我找到了这个片段并且博客和页面之间的区别有效,问题是包含行
<?php
if(is_page()){
echo 'Foo';
include ('../css/above-the-fold-contact.css.php');
echo 'Example: one';
}
else{
echo 'Foo something else';
include ('../css/above-the-fold-blog.css.php');
echo 'Example: two';
}
?>
它确实在正确的页面中注入了正确的文件,但我需要将 include 包裹在 <style>
标签周围,不这样做会导致文件的内容以纯文本形式注入。我怎么做?语法是什么?非常感谢任何帮助,非常感谢!
<?php
echo '<style type="text/css">';
if( is_page() ) { include '../css/above-the-fold-contact.css.php'; }
else { include '../css/above-the-fold-blog.css.php'; }
echo '</style>';
EDIT :简单提一下 - 如果你的 CSS 不是动态生成的,那么有更好的方法来做到这一点(比如 wp_enqueue_style
,例如 )