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

如何在内联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?

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料