WordPress.org

Forums

Attachments
Show attachments on specific page template (2 posts)

  1. Dave Loodts
    Member
    Posted 2 years ago #

    Hey, i want to share my solution to connect the attachment plugin only to a specific page template.
    Thanks to: http://wordpress.stackexchange.com/questions/18122/toggle-admin-metabox-based-upon-chosen-page-template

    Put his code in functions.php

    add_action('admin_enqueue_scripts', 'my_admin_script');
    function my_admin_script()
    {
        wp_enqueue_script('my-admin', get_bloginfo('stylesheet_directory').'/js/my-admin.js', array('jquery'));
    }

    And make a new js-file like this.
    In my example; the 'template-contact.php' (Contact template) is showing the attachment plugin.

    (function($){
    $(document).ready(function() {
    
        var $page_template = $('#page_template')
            ,$metabox = $('#attachments-my_attachments_temp'); // For example
    
        $page_template.change(function() {
            if ($(this).val() == 'template-contact.php') {
                $metabox.show();
            } else {
                $metabox.hide();
            }
        }).change();
    
    });
    })(jQuery);

    Hope this helps for somebody too.

    http://wordpress.org/extend/plugins/attachments/

  2. Jonathan Christopher
    Member
    Plugin Author

    Posted 2 years ago #

    This is also facilitated in Attachments UI

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Attachments
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic

Tags

No tags yet.