Re: Inserting image from custom imagegallery

  •  08-07-2012, 7:51 AM

    Re: Inserting image from custom imagegallery

    Step 1 Defining Custom Image Sizes
    For your theme to support custom image sizes you have to edit the functions.php file found in your themes folder. Open your theme’s functions.php and check if you have a line that looks like this:
    add_action( 'after_setup_theme', 'function_name' );  
    This hook is called during a theme’s initialization. It is generally used to perform basic setup, registration, and initialization actions for a theme, where “function_name” is the name of the function to be called.
    If you found a line like that, then also find the method with the same name as the 2nd parameter from that add_action method.
    If you can’t find a line that looks like that you should add it, and also create a method names as the 2nd parameter:
    add_action( 'after_setup_theme', 'setup' );  
    function setup() {  
        // ...  
    }  
    Now to enable post thumbnails for your theme add the following lines in the method defined above:
    function setup() {  
        // ...  
          
        add_theme_support( 'post-thumbnails' ); // This feature enables post-thumbnail support for a theme  
        // To enable only for posts:  
        //add_theme_support( 'post-thumbnails', array( 'post' ) );  
        // To enable only for posts and custom post types:  
        //add_theme_support( 'post-thumbnails', array( 'post', 'movie' ) );  
          
        // Register a new image size.  
        // This means that WordPress will create a copy of the post image with the specified dimensions  
        // when you upload a new image. Register as many as needed.  
        // Adding custom image sizes (name, width, height, crop)  
        add_image_size( 'featured-image', 620, 200, true );  
          
        // ...  
    }  
    Step 2 Displaying Images With Custom Sizes
    Insert Custom Sized Image Into Post Using Media Gallery
    To insert an image inside a post or page from the media gallery insert the following filter into the functions.php file:
    view plaincopy to clipboardprint?
    add_filter( 'image_size_names_choose', 'custom_image_sizes_choose' );  
    function custom_image_sizes_choose( $sizes ) {  
        $custom_sizes = array(  
            'featured-image' => 'Featured Image'  
        );  
        return array_merge( $sizes, $custom_sizes );  
    }  


    Best Regards,
    Navin Patel-Affiliate Manager
    Minisuit Affiliate Program
    Minisuit DOT com
View Complete Thread