Solved

Conditional in Wordpress child theme

Posted on 2011-03-02
5
364 Views
Last Modified: 2012-05-11
My site is at http://www.aurorahealthaccess.org -- it's built on a child theme for Twenty Ten. I've got some conditions set for how div#branding area is served up, and it's working properly on all traditional pages but not on any single/singular/post/blog pages. Basically I want those post pages to behave just like any other page (except is_front_page because its div#content is handled differently). My template code is below.

I think it's as easy as adding another condition to the code in line 5 but I can't seem to figure it out. Any help would be much appreciated. Thanks in advance.
<?php
get_header(); ?>

        <div id="container">
			<?php if ( !is_front_page() ) { ?>
                <div id="branding" role="banner">
                    <?php $heading_tag = ( is_home() || is_front_page() ) ? 'h1' : 'div'; ?>
                    <<?php echo $heading_tag; ?> id="site-title">
                        <span>
                            <a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
                        </span>
                    </<?php echo $heading_tag; ?>>
                    <div id="site-description"><?php bloginfo( 'description' ); ?></div>
    
                    <?php
                        // Check if this is a post or page, if it has a thumbnail, and if it's a big one
                        if ( is_singular() &&
                                has_post_thumbnail( $post->ID ) &&
                                ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
                                $image[1] >= HEADER_IMAGE_WIDTH ) :
                            // Houston, we have a new header image!
                            echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
                        else : ?>
                            <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
                        <?php endif; ?>
                </div><!-- #branding -->
			<?php } ?>

Open in new window

0
Comment
Question by:PitaMaria
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 31

Expert Comment

by:gwkg
ID: 35028763
The default file that displays a single post page is single.php.

Since you are using a child theme, if you do not create a new single.php file, your theme is using the one from twentyten.

If you weren't using a child theme and left out single.php, your theme would use index.php to display a single post page.
0
 

Author Comment

by:PitaMaria
ID: 35029012
@gwkg: That worked for all single post entries -- thanks for that -- but not for author, category, comments, tag or posts pages. I thought single.php covered those pages, no? Do I need to save child versions of each of those too?
0
 
LVL 31

Assisted Solution

by:gwkg
gwkg earned 500 total points
ID: 35032409
pages.php covers pages

archive.php will cover the rest except for comments.

comments.php is the default for comments, but that file is called with comments_template(); like header.php is called with get_header();  

This should help: http://codex.wordpress.org/Template_Hierarchy
0
 

Accepted Solution

by:
PitaMaria earned 0 total points
ID: 35148700
@gwkg: TwentyTen doesn't have a pages.php but it does have page.php -- is that what you meant?

@everyone: Some styling issues aside I've managed to get all non-"page" pages to display my banner, all except for my front page at http://www.aurorahealthaccess.org/blog/. The PHP code I'm using in page.php of my child theme is below -- the problem may reside there but I'm not sure. Please help!
<div id="container">
			<?php if ( !is_front_page() ) { ?>
                <div id="branding" role="banner">
                    <?php $heading_tag = ( is_home() || is_front_page() ) ? 'h1' : 'div'; ?>
                    <<?php echo $heading_tag; ?> id="site-title">
                        <span>
                            <a href="<?php echo home_url( '/' ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a>
                        </span>
                    </<?php echo $heading_tag; ?>>
                    <div id="site-description"><?php bloginfo( 'description' ); ?></div>
    
                    <?php
                        // Check if this is a post or page, if it has a thumbnail, and if it's a big one
                        if ( is_singular() &&
                                has_post_thumbnail( $post->ID ) &&
                                ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
                                $image[1] >= HEADER_IMAGE_WIDTH ) :
                            // Houston, we have a new header image!
                            echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
                        else : ?>
                            <img src="<?php header_image(); ?>" width="<?php echo HEADER_IMAGE_WIDTH; ?>" height="<?php echo HEADER_IMAGE_HEIGHT; ?>" alt="" />
                        <?php endif; ?>
                </div><!-- #branding -->
			<?php } ?>

			<?php if ( is_front_page() ) { ?>
                <div id="content" class="front" role="main">
			<?php } else { ?>
                <div id="content" role="main">
			<?php } ?>

Open in new window

0
 

Author Closing Comment

by:PitaMaria
ID: 35997894
I ended up figuring it out. Thanks for the help, @gwkg.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question