将数组字符串添加到stylesheet.php

时间:2014-07-12 12:34:35

标签: php wordpress

我有一个stylesheet.php用于更改网站上的样式。我在wordpress管理主题页面中进行了大部分更改,因此我使用的代码如

.div {
    height:<?php echo $layout_options['div-height']; ?>;
}

我还需要在页面顶部获取信息

<?php $layout_options       = get_option ( 'layout_options' ); ?>

我现在正在尝试编辑字体,为此,我需要根据我在管理页面下拉列表中选择的内容来更改@import和字体系列。

这是我的功能:

function span_font_callback() {
$layout_options = (array) get_option( 'layout_options' );
$fonts = get_fonts();
$current = 'arial';

if ( isset( $layout_options['span-font'] ) )
    $current = $layout_options['span-font'];

?>
    <select name="layout_options[span-font]">
      <option value="default">Please select an option</option>
      <?php foreach( $fonts as $key => $font ): ?>
        <option <?php if($key == $current) echo "SELECTED"; ?> value="<?php echo $key; ?>"><?php echo $font['name']; ?></option>
      <?php endforeach; ?>
    </select>
    <input type="text" name="layout_options[span_font_size]" size="6" value="<?php echo $layout_options['span_font_size']; ?>" placeholder="Size"/>
    <input type="text" name="layout_options[span_font_colour]" size="6" value="<?php echo $layout_options['span_font_colour']; ?>" placeholder="Colour"/>

<?php   
}

这是get_fonts()数组

function get_fonts() {
$fonts = array(
    'arial' => array(
        'name' => 'Arial',
        'font' => '',
        'css' => "'Arial', sans-serif"
    ),
    'Montez' => array(
        'name' => 'Montez',
        'font' => '@import url(http://fonts.googleapis.com/css?family=Montez);',
        'css' => "'Montez', cursive"
    ),
    'Open Sans' => array(
        'name' => 'Open Sans',
        'font' => '@import url(http://fonts.googleapis.com/css?family=Open+Sans);',
        'css' => "'Open Sans', sans-serif"
    ),
    'ubuntu' => array(
        'name' => 'Ubuntu',
        'font' => '@import url(https://fonts.googleapis.com/css?family=Ubuntu);',
        'css' => "'Ubuntu', sans-serif"
    ),
    'lobster' => array(
        'name' => 'Lobster',
        'font' => '@import url(http://fonts.googleapis.com/css?family=Lobster);',
        'css' => "'Lobster', cursive"
    )
);

return apply_filters( 'get_fonts', $fonts );

}

这是我的stylesheet.php

<?php $layout_options       = get_option ( 'layout_options' ); ?>

@import url(http://fonts.googleapis.com/css?family=Lobster);
.hero_text {
text-align: right;
padding-left: 5px;
display: inline;
float: right;
clear: both;
position: fixed;
right: 0;
font-family: <?php echo $layout_options['h1-font']; ?>;
font-size: <?php echo $layout_options['h1_font_size']; ?>;
color: <?php echo $layout_options['h1_font_colour']; ?>;
line-height: 20px;
}

我需要替换@impot行

@import url(http://fonts.googleapis.com/css?family=Lobster);

类似

<?php echo $layout_options['h1-font-import']; ?>

因此,当我更改下拉列表时,这将根据所选内容而改变

我有什么想法可以做到这一点吗?

0 个答案:

没有答案