WordPress.org

Ready to get started?Download WordPress

Forums

Theme Options - CSS div Background Image (4 posts)

  1. whispere
    Member
    Posted 2 years ago #

    What code do I need to be able to change a background image of a particular div in the Themes Option Panel.

    I wanted to set it up so I would only have to type the name of the correct image I want it to put in the background.
    OPTIONS.PHP

    $options[] = array( "name" => "Menu Background",
    						"desc" => "silver, green, black",
    						"id" => "menu_template",
    						"type" => "textarea");

    If I were changing something in a php file I know I could just put <?php echo of_get_option('menu_template'); ?>right where I want it to insert the text, but what it the most efficient way to target the background style so It can be switched out.

    Is there a good way of adding the style w/php?

    .navbar {
    background: url(images/bar.png) top left repeat;
    width: 800px;
    height: 35px;margin: 0px auto;
    }

    What I want to do is basically

    .navbar {
    background: url(images/<?php echo of_get_option('menu_template'); ?>.png) top left repeat;
    width: 800px;
    height: 35px;margin: 0px auto;
    }

    But I know unicorns don't exist and I know I can't add the php to the css like that so please help. I know this is a stupid question to most of you but I am such a newbie w/ wordpress & php

  2. shirazdrum
    Member
    Posted 2 years ago #

    Unless you are making a function for a custom theme and letting the user insert the image in the options, just put the link to the image in the url(), no need for anything else.

    Another way would be to copy that image to your stylesheet directory in a folder called "images" and then you call it like:

    background: #YOUR COLOR CODE url(images/blahblah.png) top left repeat;

  3. whispere
    Member
    Posted 2 years ago #

    Thanks for the reply, and actually I am making It for someone else. I know its a lot simpler for me just to go in and change it manually but I want them to be able to switch the menu when they would like themselves. Its something they have requested and I haven't created themes with theme options before.

    I have been able to add every other part needed in the themes option except this one.

  4. dougwalker619
    Member
    Posted 1 year ago #

    I accomplished this with inline css...
    <div class="banner" style="background:url('<?php echo $newmatic_options['themebanner']; ?>') repeat;">

Topic Closed

This topic has been closed to new replies.

About this Topic