• Resolved waterworks2

    (@waterworks2)


    I want to change the background color of my navigation bar on one page only. I’m a newbie so please excuse me if this question is a dumb one.

    I’m thinking I need to put a conditional statement in the page.php along with some css styling. I tried the coding below but it didn’t do anything. What am I doing wrong here besides everything? ??

    1. div id to affect background color for nav is #access
    2. using static home page: https://www.mydomain.com/home/

    Here is regular coding in my page.php

    <?php
    /**
     * The template for displaying all pages.
     *
     * This is the template that displays all pages by default.
     * Please note that this is the WordPress construct of pages
     * and that other 'pages' on your WordPress site will use a
     * different template.
     *
     * @package WordPress
     * @subpackage Twenty_Ten
     * @since Twenty Ten 1.0
     */
    
    get_header(); ?>
    
    		<div id="container">
    			<div id="content" role="main">
    
    				<?php if ( is_front_page() ) { ?>
    					<h2 class="entry-title"><?php the_title(); ?></h2>
    				<?php } else { ?>
    					<h1 class="entry-title"><?php the_title(); ?></h1>
    				<?php } ?>
    
    				<?php if (is_page(array('latest-news','news'))) { ?>
    				<?php include('includes/news.php'); ?>
    				<?php } ?>
    
    				<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
    
    					<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    
    						<div class="entry-content">
    							<?php the_content(); ?>
    							<?php wp_link_pages( array( 'before' => '<div class="page-link">' . __( 'Pages:', 'twentyten' ), 'after' => '</div>' ) ); ?>
    							<?php edit_post_link( __( 'Edit', 'twentyten' ), '<span class="edit-link">', '</span>' ); ?>
    						</div><!-- .entry-content -->
    					</div><!-- #post-## -->
    
    					<?php comments_template( '', true ); ?>
    				<?php endwhile; ?>
    
    			</div><!-- #content -->
    		</div><!-- #container -->
    
    	<?php get_sidebar(); ?>
    <?php get_footer(); ?>

    And here is the coding I tried to insert:

    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    
    <?php if (is_page('home') ):
    	  // home ?>
    	<style type="text/css">
    	#access {background: -moz-linear-gradient(center top , #FEFEFE 0%, #121212 100%) repeat scroll 0 0 transparent;}
    	</style>
    
    <?php endif; // end the if, no background color change if not home ?>

Viewing 11 replies - 1 through 11 (of 11 total)
  • Are you using a child theme?

    Thread Starter waterworks2

    (@waterworks2)

    Hmmm…good question. I’m not sure. How do I tell? I did not build this theme but inherited the job of making some updates to it. Should I provide screenshot of the theme’s directory?

    I looked up ‘child theme’ here:
    https://codex.www.ads-software.com/Child_Themes

    and I don’t think I am using a child theme.

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Make sure you use a Child Theme when making modifications to the theme’s files, otherwise changes you make will erase once the theme updates.

    Thread Starter waterworks2

    (@waterworks2)

    That’s an excellent point Andrew! Thanks for that. I should probably set up a child theme for this one page then, although I’m not sure the best way to go about that. Perhaps

    /main-theme/
    /main-theme-child/

    then set up a css file inside with an information header, along with styling for #access (my div for nav)?

    Yes, you are right. The header section in the child style.css file has to be exactly correct — so that it pulls the styles from the parent — see the link posted above for how-to.

    Thread Starter waterworks2

    (@waterworks2)

    Ok, so I see how to set up a child theme, but how do I make that theme active for only one page? Should the theme show up under the: Page Attributes > Template (box on the right of each page in admin area)?

    I have:

    /main-theme/
       |style.css
    
    /main-theme-child/
       |style.css

    I used the @import rule in CSS to load other sheet, then added a few bits of CSS to change a few attributes. Then I activated some other theme and then re-activated the main theme.

    Looking at the original style.css informational header for the theme, I see it was set up in 2010.

    /*
    Theme Name: main-theme
    Theme URI: https://www.ads-software.com/
    Description: The 2010 theme for WordPress is stylish, customizable, simple, and readable -- make it yours with a custom menu, header image, and background. Twenty Ten supports six widgetized areas (two in the sidebar, four in the footer) and featured images (thumbnails for gallery posts and custom header images for posts and pages). It includes stylesheets for print and the admin Visual Editor, special styles for posts in the "Asides" and "Gallery" categories, and has an optional one-column page template that removes the sidebar.
    Author: the WordPress team
    Version: 1.1
    Tags: black, blue, white, two-columns, fixed-width, custom-header, custom-background, threaded-comments, sticky-post, translation-ready, microformats, rtl-language-support, editor-style
    */

    Is this informational header still usable for the latest WP? I tried updating the style.css informational header to reflect:

    /*
    Theme Name: main-theme
    Template: main-theme
    */

    And then the child style.css to reflect:

    /*
    Theme Name: main-theme-child
    Template: main-theme
    */

    But it WP admin area gave me an error upon activating a new theme and said one of my templates was messed up. So I reuploaded the files to get it back to the way it was, but now I’m stuck on how to get this child theme working for just one page.

    Just create a bog-standard child theme and then add your CSS to the child based on the classes generated in the body tag by the parent theme.

    Thread Starter waterworks2

    (@waterworks2)

    Ok I must have had a type somewhere. I fixed the informational headers in the style.css files and now the child theme activates just fine.

    The only file I have in the child folder is the style.css.

    Thanks for the assistance esmi, but I’m still not understanding how to activate the child theme for one page only? When I activated it, of course it affected all pages.

    Yes – the child theme will be called on all pages across the site but remember that the parent’s CSS and templates still get used in they’re not over-written in the child. So the new CSS you add to the child has to be page specific. For example:

    body.page-id-174 #access {background:red;}

    will only change the nav bar’s color on the Page with the id of 174/

    Thread Starter waterworks2

    (@waterworks2)

    Ohhhh I see! Thanks ESMI! You are gentleman and a scholar! Thank you for your efforts here. Case resolved.

    Glad I could help ??

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Changing bg color of div, on just one page’ is closed to new replies.