2015-11-04 00:20
浏览 125


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'); ?>');">

    Hope it helps!

    解决 无用
    打赏 举报

相关推荐 更多相似问题