Skip to main content
added 11 characters in body
Source Link

I wish to set a featured/header image for each of my category archive pages, how would I go about doing this without hard coding iteach category into the theme?

An example of the page is at http://keswickscouts.org/section/cubs

The code form header.php is

            <div id="main-image">
        <?php
            // Check to see if the header image has been removed
            $header_image = get_header_image();
            if ( ! empty( $header_image ) ) :
        ?>
            <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
                <?php
                    if ( !is_404() && !is_attachment() ) { // Check if this is not 404 or attachment page
                        // Check if this is a post or page, if it has a post-thumbnail
                        if ( is_singular() && has_post_thumbnail( $post->ID ) && ( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) :
                        echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
                    else : ?>
                        <img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
                <?php endif; } // end check for featured image or standard header ?>
            </a>
        <?php endif; // end check for removed header image ?>
        </div><!-- end #main-image -->

I wish to set a featured/header image for each of my category archive pages, how would I go about doing this without hard coding it into the theme?

An example of the page is at http://keswickscouts.org/section/cubs

The code form header.php is

            <div id="main-image">
        <?php
            // Check to see if the header image has been removed
            $header_image = get_header_image();
            if ( ! empty( $header_image ) ) :
        ?>
            <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
                <?php
                    if ( !is_404() && !is_attachment() ) { // Check if this is not 404 or attachment page
                        // Check if this is a post or page, if it has a post-thumbnail
                        if ( is_singular() && has_post_thumbnail( $post->ID ) && ( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) :
                        echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
                    else : ?>
                        <img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
                <?php endif; } // end check for featured image or standard header ?>
            </a>
        <?php endif; // end check for removed header image ?>
        </div><!-- end #main-image -->

I wish to set a featured/header image for each of my category archive pages, how would I go about doing this without hard coding each category into the theme?

An example of the page is at http://keswickscouts.org/section/cubs

The code form header.php is

            <div id="main-image">
        <?php
            // Check to see if the header image has been removed
            $header_image = get_header_image();
            if ( ! empty( $header_image ) ) :
        ?>
            <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
                <?php
                    if ( !is_404() && !is_attachment() ) { // Check if this is not 404 or attachment page
                        // Check if this is a post or page, if it has a post-thumbnail
                        if ( is_singular() && has_post_thumbnail( $post->ID ) && ( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) :
                        echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
                    else : ?>
                        <img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
                <?php endif; } // end check for featured image or standard header ?>
            </a>
        <?php endif; // end check for removed header image ?>
        </div><!-- end #main-image -->
reworded question
Source Link

I'm tryingI wish to set a certain featured/header image to appear onfor each of my category archive pages - dependant upon the category- but have, as yet been unable to dohow would I go about doing this without hard coding it into the theme?

An example of the page is at http://keswickscouts.org/section/cubs

The code form header.php is

            <div id="main-image">
        <?php
            // Check to see if the header image has been removed
            $header_image = get_header_image();
            if ( ! empty( $header_image ) ) :
        ?>
            <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
                <?php
                    if ( !is_404() && !is_attachment() ) { // Check if this is not 404 or attachment page
                        // Check if this is a post or page, if it has a post-thumbnail
                        if ( is_singular() && has_post_thumbnail( $post->ID ) && ( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) :
                        echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
                    else : ?>
                        <img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
                <?php endif; } // end check for featured image or standard header ?>
            </a>
        <?php endif; // end check for removed header image ?>
        </div><!-- end #main-image -->

I'm trying to set a certain featured image to appear on my category pages - dependant upon the category- but have, as yet been unable to do this without hard coding

An example of the page is at http://keswickscouts.org/section/cubs

The code form header.php is

            <div id="main-image">
        <?php
            // Check to see if the header image has been removed
            $header_image = get_header_image();
            if ( ! empty( $header_image ) ) :
        ?>
            <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
                <?php
                    if ( !is_404() && !is_attachment() ) { // Check if this is not 404 or attachment page
                        // Check if this is a post or page, if it has a post-thumbnail
                        if ( is_singular() && has_post_thumbnail( $post->ID ) && ( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) :
                        echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
                    else : ?>
                        <img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
                <?php endif; } // end check for featured image or standard header ?>
            </a>
        <?php endif; // end check for removed header image ?>
        </div><!-- end #main-image -->

I wish to set a featured/header image for each of my category archive pages, how would I go about doing this without hard coding it into the theme?

An example of the page is at http://keswickscouts.org/section/cubs

The code form header.php is

            <div id="main-image">
        <?php
            // Check to see if the header image has been removed
            $header_image = get_header_image();
            if ( ! empty( $header_image ) ) :
        ?>
            <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
                <?php
                    if ( !is_404() && !is_attachment() ) { // Check if this is not 404 or attachment page
                        // Check if this is a post or page, if it has a post-thumbnail
                        if ( is_singular() && has_post_thumbnail( $post->ID ) && ( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) :
                        echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
                    else : ?>
                        <img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
                <?php endif; } // end check for featured image or standard header ?>
            </a>
        <?php endif; // end check for removed header image ?>
        </div><!-- end #main-image -->
Source Link

Category index featured image

I'm trying to set a certain featured image to appear on my category pages - dependant upon the category- but have, as yet been unable to do this without hard coding

An example of the page is at http://keswickscouts.org/section/cubs

The code form header.php is

            <div id="main-image">
        <?php
            // Check to see if the header image has been removed
            $header_image = get_header_image();
            if ( ! empty( $header_image ) ) :
        ?>
            <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
                <?php
                    if ( !is_404() && !is_attachment() ) { // Check if this is not 404 or attachment page
                        // Check if this is a post or page, if it has a post-thumbnail
                        if ( is_singular() && has_post_thumbnail( $post->ID ) && ( $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) && $image[1] >= HEADER_IMAGE_WIDTH ) :
                        echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
                    else : ?>
                        <img src="<?php header_image(); ?>" height="<?php echo get_custom_header()->height; ?>" width="<?php echo get_custom_header()->width; ?>" alt="" />
                <?php endif; } // end check for featured image or standard header ?>
            </a>
        <?php endif; // end check for removed header image ?>
        </div><!-- end #main-image -->