douji6940
2012-11-21 09:49
浏览 102
已采纳

如何在内联html中使用变量路径获取背景图像?

I have my own wordpress template with option setting. My option setting having option for background Image path. I saved this option value in variable .Now how i can add this option setting value to get background Image for specific div class?

图片转代码服务由CSDN问答提供 功能建议

我有自己的wordpress模板,带有选项设置。 我的选项设置有背景图像路径选项。 我将此选项值保存在变量中。现在我如何添加此选项设置值以获取特定div类的背景图像?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dos71253 2012-12-07 08:05
    已采纳

    You'll need a page that you can put both CSS and PHP on, like header.php in your template. Be sure to note that this CSS hack is there so that you can re-add it when you update the theme.

    Now, in your header.php file, just before the </head> tag, add this:

    <style type='text/css'>
        /* div selector */ {
            background: url(<?php echo get_option("option_name"); ?>);
        }
    </style>
    </head>
    

    You'll need to add a CSS selector to select the div you want to have tha background image, and you'll need to make sure that the background image links correctly. You may need to add /wp-content/ or similar things to the CSS or the option value if the image doesn't link correctly at first.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题