dounabi6295 2015-11-04 00:20
浏览 129
已采纳

WordPress:每个<section>的动态背景图像

I'm creating a page with 5 <section>s of content, each 720px in height. I would like to have 5 different background images (i.e. one for each section), as well as the ability to change the image for a given section via WordPress administration.

I'm using CSS to set the background image for each section, e.g.:

.section-1 {
    position: relative;
    background: url("images/section-1-bg.jpg") no-repeat;
    background-size: cover;
    height: 720px;
}

I've looked at countless plugins and examples, but have yet to find anything remotely resembling to what I'm trying to do. I've also read the WordPress Codex exhaustively, searching for answers to what I consider a very basic requirement.

Can someone please point me in the right direction on how to modularize my code and create a small plugin to upload/select new background images for when I decide I want to change a given section?

  • 写回答

1条回答 默认 最新

  • douyan1970 2015-11-04 00:35
    关注

    You could add the image inline and then use advanced custom fields or something similar to add the image via the administration, like this:

    <section class="section-1"
    style="background-image:url('<?php the_field('field_name'); ?>');">
    </section>
    

    Hope it helps!

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

报告相同问题?

悬赏问题

  • ¥15 这个公式写进SIMULINK中的function模块的代码中应该是什么样的
  • ¥15 javaweb登陆的网页为什么不能正确连接查询数据库
  • ¥15 数学建模数学建模需要
  • ¥15 已知许多点位,想通过高斯分布来随机选择固定数量的点位怎么改
  • ¥20 nao机器人语音识别问题
  • ¥15 怎么生成确定数目的泊松点过程
  • ¥15 layui数据表格多次重载的数据覆盖问题
  • ¥15 python点云生成mesh精度不够怎么办
  • ¥15 QT C++ 鼠标键盘通信
  • ¥15 改进Yolov8时添加的注意力模块在task.py里检测不到