WordPress.org

Ready to get started?Download WordPress

Forums

Genesis Grid
[resolved] Filter The Image for CPT archive (4 posts)

  1. WPSpeak
    Member
    Posted 1 year ago #

    Hi Bill,

    How do I filter the featured image for speficic cpt archive?
    The featured image on the settings page will be used sidewide (depends on the archive page I tick on the settings page).

    I've an "Image" cpt and on the archive page for image cpt, I want it to have another image size, different from other archive pages.

    http://wordpress.org/extend/plugins/genesis-grid-loop/

  2. WPSpeak
    Member
    Posted 1 year ago #

    Got some rough ideas, but not sure exactly,
    So from you blogpost, I can see these codes (from the Advance example):

    /**
     * Grid Image Sizes
     *
     */
    function be_grid_image_sizes() {
    	add_image_size( 'be_grid', 175, 120, true );
    	add_image_size( 'be_feature', 570, 333, true );
    }
    add_action( 'genesis_setup', 'be_grid_image_sizes', 20 );
    
    /**
     * Grid Loop Featured Image
     *
     * @param string image size
     * @return string
     */
    function be_grid_loop_image( $image_size ) {
    	global $wp_query;
    	$grid_args = be_grid_loop_pagination();
    	if( ! $grid_args )
    		return $image_size;
    
    	// Feature
    	if( ( ! $wp_query->query_vars['paged'] && $wp_query->current_post < $grid_args['features_on_front'] ) || ( $wp_query->query_vars['paged'] && $wp_query->current_post < $grid_args['features_inside'] ) )
    		$image_size = 'be_feature';
    
    	if( ( ! $wp_query->query_vars['paged'] && $wp_query->current_post > ( $grid_args['features_on_front'] - 1 ) ) || ( $wp_query->query_vars['paged'] && $wp_query->current_post > ( $grid_args['features_inside'] - 1 ) ) )
    		$image_size = 'be_grid';
    
    	return $image_size;
    }
    add_filter( 'genesis_pre_get_option_image_size', 'be_grid_loop_image' );

    Ok, on the image-archive.php, I want to have a feature. Just grid. So I need to put the code above, and.. Do I just need to remove this part?

    add_image_size( 'be_feature', 570, 333, true );
    and this part

    // Feature
    	if( ( ! $wp_query->query_vars['paged'] && $wp_query->current_post < $grid_args['features_on_front'] ) || ( $wp_query->query_vars['paged'] && $wp_query->current_post < $grid_args['features_inside'] ) )
    		$image_size = 'be_feature';
  3. Bill Erickson
    Member
    Plugin Author

    Posted 1 year ago #

    So do you want a different image size used for the 'feature' posts on the image custom post type archive? This code will change them to the 'be_large' image size, and defines what that is.

    Add this to your theme's functions.php (without the <?php at the top): https://gist.github.com/4511884

  4. WPSpeak
    Member
    Posted 1 year ago #

    Awesome. Just what I want. Thanks for your help.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags