WordPress.org

Forums

New to 2011 Theme, need an "if" statement to replace header image with slider (6 posts)

  1. Native Imaging
    Member
    Posted 3 years ago #

    New to 2011 Theme, need an "if" statement to replace header image with slider.
    Only need thi to work for the home page.
    I used to use something like this for the 2010 theme

    <?php
      if (is_front_page() ) {
        echo '<div id="wrapperHome">';
    	}
    	else {
    	echo '<div id="wrapper">';
      }

    What i need to to have an "if" statement to replace the default 2011 header with the slider only for the home page. I used to just call it in the "Home" page template I made specifically for the home page

    <?php echo slider_pro(1); ?>

    I could move the 2011 default if statement in to the page templates 7 just replace them there, but looking for a cleaner way of implementing the "if" statement for the header if the current page (is_front_page() ).

    Here's the code below in the default 2011 theme:

    <?php
    				// Check to see if the header image has been removed
    				$header_image = get_header_image();
    				if ( $header_image ) :
    					// Compatibility with versions of WordPress prior to 3.4.
    					if ( function_exists( 'get_custom_header' ) ) {
    						// We need to figure out what the minimum width should be for our featured image.
    						// This result would be the suggested width if the theme were to implement flexible widths.
    						$header_image_width = get_theme_support( 'custom-header', 'width' );
    					} else {
    						$header_image_width = HEADER_IMAGE_WIDTH;
    					}
    					?>
    			<a>">
    				<?php
    					// The header image
    					// 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 ), array( $header_image_width, $header_image_width ) ) ) &&
    							$image[1] >= $header_image_width ) :
    						// Houston, we have a new header image!
    						echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
    					else :
    						// Compatibility with versions of WordPress prior to 3.4.
    						if ( function_exists( 'get_custom_header' ) ) {
    							$header_image_width  = get_custom_header()->width;
    							$header_image_height = get_custom_header()->height;
    						} else {
    							$header_image_width  = HEADER_IMAGE_WIDTH;
    							$header_image_height = HEADER_IMAGE_HEIGHT;
    						}
    						?>
    					<img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />
    				<?php endif; // end check for featured image or standard header ?>
    			</a>
    			<?php endif; // end check for removed header image ?>

    // ANY HELP WOULD BE GREATLY APPRECIATED!! THANX!!!!

    [ Moderator note: Please be sure to wrap code properly with backticks - ie use the code button in future ]

  2. Michael
    Forum Moderator
    Posted 3 years ago #

    change this section (the few lines right at the beginning of your posted code):

    <?php
    				// Check to see if the header image has been removed
    				$header_image = get_header_image();
    				if ( $header_image ) :

    to:

    <?php 				// Check to see if the header image has been removed
    				$header_image = get_header_image();
    //check for front page and show slider
    if( is_front_page() ) :
    echo slider_pro(1); 
    
    //otherwise check for header image
    				elseif ( $header_image ) :
  3. Native Imaging
    Member
    Posted 3 years ago #

    Cool, thank you!! Going to try it right now...

    I had one other question about this if statement..

    Lets say, I have a "Pictures" page for the site that would use another slider specifically for picture posts and have "echo slider_pro(2);" for that page... how would a create a hook for that page like the "is_front_page() )"? to something such as "is_pictures_page() )"?

    If thats possible. Not sure if I would need to add custom hooks for that, or a separate template?

    Hopefully I made enough sense to understand that.

    Thanx again for your help! :)

  4. Michael
    Forum Moderator
    Posted 3 years ago #

    from:

    if( is_front_page() ) :
    echo slider_pro(1); 
    
    //otherwise check for header image

    to:

    if( is_front_page() ) :
    echo slider_pro(1);
    elseif( is_page('pictures') ) :
    echo slider_pro(2);
    
    //otherwise check for header image

    http://codex.wordpress.org/Conditional_Tags

  5. Native Imaging
    Member
    Posted 3 years ago #

    Wow, thank you! You have been so much help. I definitely learned something very useful with this info & the conditional tags page.
    Everything worked the way it should have, except, it seems I'm having a conflict with the javascript or php... not sure exactly..
    here's the site:
    http://n8ryan.com/
    http://n8ryan.com/pictures/

    & here's what i have in the header: (Any help would be greatly appreciated, so close to using this method :))

    <?php // Check to see if the header image has been removed
    $header_image = get_header_image();
    //check for front page and show slider
    if( is_front_page() ) :
    echo slider_pro(1);
    elseif( is_page('pictures') ) :
    echo slider_pro(2);

    //otherwise check for header image
    elseif ( $header_image ) :
    // Compatibility with versions of WordPress prior to 3.4.
    if ( function_exists( 'get_custom_header' ) ) {
    // We need to figure out what the minimum width should be for our featured image.
    // This result would be the suggested width if the theme were to implement flexible widths.
    $header_image_width = get_theme_support( 'custom-header', 'width' );
    } else {
    $header_image_width = HEADER_IMAGE_WIDTH;
    }
    ?>
    ">
    <?php
    // The header image
    // 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 ), array( $header_image_width, $header_image_width ) ) ) &&
    $image[1] >= $header_image_width ) :
    // Houston, we have a new header image!
    echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
    else :
    // Compatibility with versions of WordPress prior to 3.4.
    if ( function_exists( 'get_custom_header' ) ) {
    $header_image_width = get_custom_header()->width;
    $header_image_height = get_custom_header()->height;
    } else {
    $header_image_width = HEADER_IMAGE_WIDTH;
    $header_image_height = HEADER_IMAGE_HEIGHT;
    }
    ?>
    <img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />
    <?php endif; // end check for featured image or standard header ?>

    <?php endif; // end check for removed header image ?>

  6. Michael
    Forum Moderator
    Posted 3 years ago #

    I see only the header image in both cases; is that the problem?

    please paste the full code of header.php into a http://pastebin.com/ and post the link to it here - see http://codex.wordpress.org/Forum_Welcome#Posting_Code

Topic Closed

This topic has been closed to new replies.

About this Topic