WordPress.org

Ready to get started?Download WordPress

Forums

Theme customization for homepage background color (11 posts)

  1. gizmogarrett21
    Member
    Posted 1 year ago #

    I'm using a theme which offers a custom option to create a background. The problem is that the background appears sitewide and we only want it for the homepage. I'm a little out of my element here and could use any sort of support anyone can give.

    The code as it appears now to retrieve the background image or color:
    <?php if($bg_image <> '') { ?>url(../images/uploads/<?php echo $bg_image; ?>) <?php echo $bg_repeat; ?><?php } ?> 0 <?php echo $bg_top_offset; ?>px #<?php echo $bg_color; ?>;

    I would like to modify this to query for the homepage first and echo $home_bg_image or $home_bg_color and perform the above code if those things aren't present. Can anyone help me with this if statement since I know nothing about how to set this up?

  2. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    Try using the is_home conditional tag, an example is at link (backup any files before editing)

  3. gizmogarrett21
    Member
    Posted 1 year ago #

    Thanks for the response. My problem is that I don't know what the rest of that would look like. I tried several things, none of which worked. Can you frame something for me that I could build off of? The link you gave is helpful if you know how php syntax works which unfortunately I don't.

    I guess was thinking something along the lines of: <?php if is_front_page() {0 <?php echo $bg_top_offset; ?>px #<?php echo $home_bg_color; } ?> else{<?php if($bg_image <> '') { ?>url(../images/uploads/<?php echo $bg_image; ?>) <?php echo $bg_repeat; ?><?php } ?> 0 <?php echo $bg_top_offset; ?>px #<?php echo $bg_color; ?>;

    Does that make sense? Or do I need an elseif? Thanks again for your help.

  4. JarretC
    Member
    Posted 1 year ago #

    You should just be able to add is_home along with the $bg_image check. So something like...

    <?php if ( $bg_image <> '' && is_home() ) { ?>

    should cover it

  5. gizmogarrett21
    Member
    Posted 1 year ago #

    Jarrett, thanks for the help. That seems like it might work but the problem I have is that I want to give the home page one color and the rest of the pages another color. How about throwing an else statement in there? I tried the following and it didn't work. Ideas?

    <?php if($bg_image <> '' && is_home() ) { ?>url(../images/uploads/<?php echo $bg_image; ?>) <?php echo $bg_repeat; ?><?php } ?> 0 <?php echo $bg_top_offset; ?>px #666; else{<?php echo $bg_color; ?>} ;

  6. JarretC
    Member
    Posted 1 year ago #

    <?php if( $bg_image <> '' && is_home() ) { ?>
    url(../images/uploads/<?php echo $bg_image; ?>)
    <?php echo $bg_repeat; } ?> 0
    <?php echo $bg_top_offset; ?>px
    <?php if ( is_home() ) { '#666;' } else { echo '#' . $bg_color; } ?>

    Try that and let me know if it works for you.

  7. gizmogarrett21
    Member
    Posted 1 year ago #

    Nope, that breaks it.

  8. JarretC
    Member
    Posted 1 year ago #

    Define breaks it.

  9. gizmogarrett21
    Member
    Posted 1 year ago #

    Right, my bad. Here is the page with the code from my very first post, and here is the page with the last code that you gave me.

  10. JarretC
    Member
    Posted 1 year ago #

    Whoops, try an echo before '#666;'

    <?php if ( is_home() ) { echo '#666;'; } else { echo '#' . $bg_color; } ?>

  11. gizmogarrett21
    Member
    Posted 1 year ago #

    It seems that we are almost there. The code isn't picking up the #666 though. The homepage still picks up whatever is assigned to $bg_color. As a random thought of 'what if...?', I tried changing the is_home to is_front_page and that didn't work either.

Topic Closed

This topic has been closed to new replies.

About this Topic