WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding css styles in themes via text input in admin panel w/php? (6 posts)

  1. jamesg40
    Member
    Posted 1 year ago #

    I am building a theme in my localhost (wamp) and I have a few options set-up in an admin panel that I have created. I have most of them working with the exception of 2 that I cant seem to get top work properly. What I am trying to do is allow the user to say put in a hex value to change the colors of say the text for all h3 tags or for instance, simply add the url to a background image for say the featured bar or the footer. So I have created my arrays and have tried a few different ways of getting it to print but I am having no luck, Here are the snippets I have so far and how I am trying to use them, could someone please let me know if this is wrong and if so how can I fix this? Here is my array say for the background image for the footer.

    array( "name" => "Footer Background",
        "desc" => "Enter the link to your custom footer background image. Image should be uploaded to the themes image directory and link should be entered like so images/logo.png. Do not use the forward slash before 'images' part of the link ",
        "id" => $shortname."_footer_background",
        "type" => "text",
        "std" => "images/footer-back.png"),

    Ok, so with that array, how can I assign that to the style - replacing the default background image with the link they input?
    I have tried a few modifications of this code but no luck so far, here is what I was altering... I have included the original without my alterations.

    function header_style() {
    if(!get_header_image() ) return;
    ?>
    <style type="text/css">
    #featured-back{
    	background: url(<?php header_image(); ?>) no-repeat !important;
    
    }
    
    </style>
    <?php
    }

    is there a better way of doing this or am I hoping for something that can not be accomplished without writing a style.php which I dont want to do? Also, can this method be used to change the color styles with just a hex input?

  2. jamesg40
    Member
    Posted 1 year ago #

    Ok, so why do some post get answered by like 30 people a minute for days and some posts go unanswered for days? I mean..... really????

  3. WPyogi
    Volunteer Moderator
    Posted 1 year ago #

    It can depend on many things such as -- how difficult or unusual the question is, who's around answering questions, how busy the forums are, what time of day it is or whether a weekend or holiday, or it could be merely random chance.

  4. Andrew
    Forum Moderator
    Posted 1 year ago #

    When I question it, I look at the 8-year-old threads on the No-Replies list and count myself lucky.

  5. jamesg40
    Member
    Posted 1 year ago #

    Yeah, I see your points. I really do, (not to be a complainer, just drunk and tired at the moment) but when you have gone around the web like 40 times looking for the answers from php sites, wordpress forums and the like - because you dont want to be a bother on the wordpress forums and then you finally end up on wordpress.org asking and still get no responses, lol, it gets kind of frustrating. Especially when you have seen a simple thing like "displaying background-image into css using php to echo a variable input field result into your theme to change a background image for a footer or the color of a text tag (say like the H1 or H3 or whatever)" in alot themes on themeforest, You know someone knows how o do it, lol. Anyways, I guess I am not really forum savy and maybe if it were so simple I would have got it working by now. I just hope someone can help me with this one because I have been working on it for 3 days and getting keyboard marks in my forehead, lol

  6. jamesg40
    Member
    Posted 1 year ago #

    OK, I figured it out, if anyone wants to know how to inject css to to class's or id's in your div containers in their theme via an input option you have built into your custom admin panel but are not totally savy on php, here it is, lol.

    lets say I have an array that I have built into my custom admin options page. It may be a background image that you would like to allow someone to upload and type in the link or a color that you will allow someone to type in #333333 into the input field. These will then be injected into your div class or id by simply doing this on the same functions sheet as your array.

    function header_style() {
    if(!get_header_image() ) return;
    ?>
    <style type="text/css">
    //write your styles in here like so and use get_option to call your array input for what ever style you like....
    
    #the-footer {
    background-image:url( <?php echo get_option('nt_footer_background'); ?> ) !important;
    background-color: #<?php echo get_option('nt_footer_background_color'); ?>;
    background-repeat: <?php echo get_option('nt_footer_background_repeat'); ?> ;
    }
    
    #cp-text h3{ 
    
    color: #<?php echo get_option('nt_copyright_text_color'); ?> ;
    
    </style>
    <?php
    }

    Notice the extra " <?php
    } " after the closing style tag, well that is important.
    I had issues with getting this to work and once i added that, it all worked fine, lol. Any ways, I hope this helps someone who like me, has a good grasp of themeing and can do some cool stuff but still doesn't understand some things and needs an answer sometime, lol

Topic Closed

This topic has been closed to new replies.

About this Topic