Last active
January 30, 2016 07:36
-
-
Save hemusyl/800379862aa560274d34 to your computer and use it in GitHub Desktop.
Multiple Featured Images in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php---------------------------- | |
3ti file lagbe | |
1. multi-post-thumbnails.php | |
2. multi-post-thumbnails-admin.js | |
3. media-modal.js | |
file 3ti functions.php te call korte hobe | |
functions.php te nicher code bosbe | |
add_image_size( 'secondary-image', 300, 156, true ); | |
if (class_exists('MultiPostThumbnails')) { | |
new MultiPostThumbnails( | |
array( | |
'label' => 'Secondary Image', | |
'id' => 'secondary-image', | |
'post_type' => 'product' | |
) | |
); | |
new MultiPostThumbnails(array( | |
'label' => '3rd Feature Image', | |
'id' => 'feature-image-3', | |
'post_type' => 'folio' | |
) | |
); | |
new MultiPostThumbnails(array( | |
'label' => '4th Feature Image', | |
'id' => 'feature-image-4', | |
'post_type' => 'folio' | |
) | |
); | |
} | |
-------------------------------------------------------------------------------- | |
---------------------------------- | |
ei code change hobe multi-post-thumbnails.php te | |
/** | |
* Enqueue admin JavaScripts | |
* | |
* @return void | |
*/ | |
public function enqueue_admin_scripts( $hook ) { | |
global $wp_version, $post_ID; | |
// only load on select pages | |
if ( ! in_array( $hook, array( 'post-new.php', 'post.php', 'media-upload-popup' ) ) ) | |
return; | |
if (version_compare($wp_version, '3.5', '<')) { | |
add_thickbox(); | |
wp_enqueue_script( "mpt-featured-image", $this->plugins_url( 'js/multi-post-thumbnails-admin.js', __FILE__ ), array( 'jquery', 'media-upload' ) ); | |
} else { // 3.5+ media modal | |
wp_enqueue_media( array( 'post' => ( $post_ID ? $post_ID : null ) ) ); | |
wp_enqueue_script( "mpt-featured-image", $this->plugins_url( 'js/multi-post-thumbnails-admin.js', __FILE__ ), array( 'jquery', 'set-post-thumbnail' ) ); | |
wp_enqueue_script( "mpt-featured-image-modal", $this->plugins_url( 'js/media-modal.js', __FILE__ ), array( 'jquery', 'media-models' ) ); | |
} | |
wp_enqueue_style( "mpt-admin-css", $this->plugins_url( 'css/multi-post-thumbnails-admin.css', __FILE__ ) ); | |
} | |
------------------------------------------------------ | |
multi-post-thumbnails.php te nicer code bosbe , uporer code er priborte. | |
public function enqueue_admin_scripts( $hook ) { | |
global $wp_version; | |
$template_url = get_bloginfo('template_url'); | |
// only load on select pages | |
if ( ! in_array( $hook, array( 'post-new.php', 'post.php', 'media-upload-popup' ) ) ) | |
return; | |
if (version_compare($wp_version, '3.5', '<')) { | |
add_thickbox(); | |
wp_enqueue_script( "mpt-featured-image", $template_url.'/js/multi-post-thumbnails-admin.js', array( 'jquery', 'media-upload' ) ); | |
} else { // 3.5+ media modal | |
wp_enqueue_media(); | |
wp_enqueue_script( "mpt-featured-image", $template_url.'/js/multi-post-thumbnails-admin.js', array( 'jquery', 'set-post-thumbnail' ) ); | |
wp_enqueue_script( "mpt-featured-image-modal", $template_url.'/js/media-modal.js', array( 'jquery', 'media-models' ) ); | |
} | |
} | |
------------------------------------------------------------------------------------------------------------------------ | |
Display code for disire place . jekhane show korte hobe | |
<?php if (class_exists('MultiPostThumbnails')) : | |
MultiPostThumbnails::the_post_thumbnail( | |
get_post_type(), | |
'secondary-image' | |
); | |
endif; ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment