WordPress.org

Ready to get started?Download WordPress

Forums

Custom Content Type Manager
[resolved] How to get specific custom image size in template (2 posts)

  1. bogastyle
    Member
    Posted 1 year ago #

    Hi Sir,

    I have some custom image sizes in my theme, like:

    if ( function_exists( 'add_theme_support' ) ) {
    	add_theme_support( 'post-thumbnails' );
    	set_post_thumbnail_size( 220, 160, true ); // Normal post thumbnails
    	add_image_size( 'small-image', 160, 160, true ); // Full size screen
    	add_image_size( 'post-big-image', 618, 400, true ); // Full size screen
    	add_image_size( 'original-image', 720, 540, true ); // Full size screen
    	add_image_size( 'header-image', 940, 300, true ); // Full size screen
    	add_image_size( 'vertical', 680, 907, false ); // Full size screen
    }

    I have custom post type "slide" for slideshow and there is custom field type image.

    I want to print out in my theme "header-image" size of image.

    My current code is:

    <?php
    					while ($my_query->have_posts()) : $my_query->the_post();
    					$slidetitle = get_the_title();
    					$slidetext = get_the_content();
    					$slideimage = get_custom_field('bod_slide_image:to_image_src', 'header-image');
    					$slidelink = get_post_meta($post->ID, bod_slide_link, true);
    					?>
                        <li>
                        	<figure>
    							<?php if( $slidelink ) : ?>
                                <a href="<?php echo $slidelink; ?>" title="<?php echo $slidetitle; ?>"><img src="<?php echo $slideimage; ?>" alt="<?php echo $slidetext; ?>" /></a>
                                <?php else : ?>
                                <img src="<?php echo $slideimage; ?>" alt="<?php echo $slidetext; ?>" />
                                <?php endif; ?>
                            </figure>
                        </li>
    					<?php endwhile; ?>

    This work if I crop image before upload.
    It is possible, some how, to upload full image and then take specific size in theme.

    http://wordpress.org/extend/plugins/custom-content-type-manager/

  2. bogastyle
    Member
    Posted 1 year ago #

    OK. I found decision.

    <?php
    		$slideimage_id = get_custom_field('bod_slide_image:raw'); // <-- get the raw post id
    		$croped_slideimage = CCTM::filter( $slideimage_id, 'to_image_tag', 'header-image'); // <-- get needed custom image size
    
    		echo $croped_slideimage; // <-- echo image tag
    	?>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic