Conditional wordpress logic is_front-page

Hi,
I’m struggling to isolate my front page for some separate styling.
I would like to use some conditional logic `<?php is_front_page(); ?>’
to change the colour of the transparent content area, but only on the front page. I have run a test (‘this is the front page’) but it shows on all pages. I am using a customised child version of page.php.

http://www.earth-wind-fire.com.au/

Any help appreciated.

1 Like

Ok I’m thinking now that I need to paste all the existing code from page.php into the ‘if’ part of the conditional statement
with the only change being the addition of a style declaration (custom-bg-site-content-color) to change the colour of the site-content area only on the front page thus:

<div id="content" class="site-content custom-bg-site-content-color" role="main">

i.e. if it’s the front page apply this style custom-bg-site-content-color to the content div.

The code within the else part of the statement is the original code unmodified.

i.e. if it’s not the front page render as normal - don’t change the colour of the content div.

Trouble is I get a parse error (unexpected ‘<’ on line 16) using this structure based on the code below:

Any help appreciated.

<?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_Thirteen
 * @since Twenty Thirteen 1.0
 */

get_header(); ?>
<?php if ( is_front_page() ) {    
    <div id="primary" class="content-area">
        <div id="content" class="site-content custom-bg-site-content-color" role="main">

            <?php /* The loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>

                <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <header class="entry-header">
                        <?php if ( has_post_thumbnail() &&  ! post_password_required() ) : ?>
                        <div class="entry-thumbnail">
                            <?php the_post_thumbnail(); ?>
                        </div>
                        <?php endif; ?>

                        <h1 class="entry-title"><?php the_title(); ?></h1>
                    </header><!-- .entry-header -->

                    <div class="entry-content">


                        <?php the_content(); ?>
                        <?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
                    </div><!-- .entry-content -->

                    <footer class="entry-meta">
                        <?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
                    </footer><!-- .entry-meta -->
                </article><!-- #post -->

                <?php comments_template(); ?>
            <?php endwhile; ?>

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
     } 

     else

     {    <div id="primary" class="content-area">
        <div id="content" class="site-content" role="main">

            <?php /* The loop */ ?>
            <?php while ( have_posts() ) : the_post(); ?>

                <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                    <header class="entry-header">
                        <?php if ( has_post_thumbnail() &&  ! post_password_required() ) : ?>
                        <div class="entry-thumbnail">
                            <?php the_post_thumbnail(); ?>
                        </div>
                        <?php endif; ?>

                        <h1 class="entry-title"><?php the_title(); ?></h1>
                    </header><!-- .entry-header -->

                    <div class="entry-content">


                        <?php the_content(); ?>
                        <?php wp_link_pages( array( 'before' => '<div class="page-links"><span class="page-links-title">' . __( 'Pages:', 'twentythirteen' ) . '</span>', 'after' => '</div>', 'link_before' => '<span>', 'link_after' => '</span>' ) ); ?>
                    </div><!-- .entry-content -->

                    <footer class="entry-meta">
                        <?php edit_post_link( __( 'Edit', 'twentythirteen' ), '<span class="edit-link">', '</span>' ); ?>
                    </footer><!-- .entry-meta -->
                </article><!-- #post -->

                <?php comments_template(); ?>
            <?php endwhile; ?>

        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>
}
 ?>

You went into HTML without leaving PHP (which is prone to happening when they’re jumbled together)

<?php if ( is_front_page() ) {    
    <div id="primary" class="content-area">

Have you tried testing for is_home - returns boolean - to set a class you can use CSS with to style the page?

Caveats here

Unfortunately is_home and is_front_page do nothing

Thanks for the tip on getting the php open and close sequence right, despite resolving these statements I couldn’t get any action on conditionally isolating the home page.

Found an answer to this: http://codex.wordpress.org/Function_Reference/body_class
Found this in the source: <body class="home page page-id-255 page-child parent-pageid-30 page-template-default logged-in admin-bar no-customize-support single-author">

So I just found the relevant div I wanted to style and did this:
.home div#content.site-content { background-color: rgba(235, 128, 171, 0.50); }
Thanks for your help, you put me on the right track when you mentioned setting a class.

1 Like

Thanks for letting us know you found an answer, @Argent

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.