voceconnect / multi-post-thumbnails

Adds multiple post thumbnails to a post type. If you've ever wanted more than one Featured Image on a post, this plugin is for you.
143 stars 63 forks source link

MultiPostThumbnail only in custom template page (metabox) #74

Closed enlego closed 9 years ago

enlego commented 9 years ago

I have several pages: About-us, Home, Proyects, etc. When I use the function

if (class_exists('MultiPostThumbnails')) {
    new MultiPostThumbnails(array('label' => 'conocenos','id' => 'imagen-conocenos','post_type' => 'page'));
    new MultiPostThumbnails(array('label' => 'Imagen 2','id' => 'imagen-2','post_type' => 'post'));
    new MultiPostThumbnails(array('label' => 'Imagen 3','id' => 'imagen-3','post_type' => 'post'));
    new MultiPostThumbnails(array('label' => 'Imagen 4','id' => 'imagen-4','post_type' => 'post'));
    new MultiPostThumbnails(array('label' => 'Imagen 5','id' => 'imagen-5','post_type' => 'post'));
}

the first one post_type=>'page' is showing in every page. How can I enable it in Home but disable it in About-us, Proyects, etc?

Thanks in advance!

matgargano commented 9 years ago

Hook a function in add_meta_boxes with a higher priority than 10 and remove_metabox with the id of page-imagen-conocenos with a context of side on the page if its the page you don't want it on (or not the page you want it on)...

enlego commented 9 years ago

Thanks matgargano. I'll paste the solution here in case someone else needs it.

// Add the following code at the end of functions.php
// remove MultiPostThumbnail for pages not using the template page "tp_conocenos.php"
add_action( 'add_meta_boxes', 'remove_img_metabox_conocenos');

function remove_img_metabox_conocenos() {
        // get the post id to check which template is usign.
        $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
        $template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
        if ($template_file != 'tp_conocenos.php') {
            remove_meta_box('page-imagen-conocenos', 'page', 'side');
        }
}