简体   繁体   English

根据.css文件更改徽标

[英]changing the logo based on .css file

I have this code in my header.php : 我在header.php中有这个代码:

    <div id="logo">
    <?php if( get_option('of_logo') != '') { ?>
    <a class="image" href="<?php echo get_option('home'); ?>/" title="Home">
        <img src="<?php echo get_option('of_logo'); ?>"  />
    </a>
    <?php } else { ?>
        <h1 class="front-page-logo"><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo('name'); ?></a></h1> 
        <h2><?php bloginfo('description'); ?></h2>
    <?php } ?>
    </div>

All works great! 一切都很棒! basically it says if the user uploads a logo image in the theme options panel, then show that image, else, show some text. 基本上它表示如果用户在主题选项面板中上传徽标图像,则显示该图像,否则显示一些文本。

Now I need to replace this: 现在我需要替换它:

    <?php } else { ?>
        <h1 class="front-page-logo"><a href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo('name'); ?></a></h1> 
        <h2><?php bloginfo('description'); ?></h2>
    <?php } ?>

with display a image based on the style.css the user choose. 显示基于用户选择的style.css的图像。 And my problem here is if I go to each css file and declare a diferent image, then if the user uploads a image also, both images show on page. 我的问题在于,如果我转到每个css文件并声明不同的图像,那么如果用户也上传了图像,则两个图像都显示在页面上。

So how can I do that? 那我该怎么办呢? thanks 谢谢

Use a an id or class on your default logo and declare the image urls in the various css files using background-image : 在默认徽标上使用id或类,并使用background-image在各种css文件中声明图像URL:

<?php } else { ?>
    <div id="default-logo"></div>
<?php } ?>

In the css files: 在css文件中:

#default-logo {
    background-image: url(".../1.jpg");
    width: 80px;
    height: 80px; /* the dimensions of your logo */
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM