WordPress.org

Forums

OptionTree
[resolved] Meta Boxes on specific theme template page (5 posts)

  1. aeboi80
    Member
    Posted 2 years ago #

    Is there any way to add a few meta boxes to say just the homepage which in my case has a custom theme page template of home-page.php

    I realize I could do this as a theme option and simply create a new option section called "Home page" and create the fields there, but I think it makes more sense from a usability perspective to place the meta boxes for the callout boxes on the homepage actually on the Home page WP edit screen.

    http://wordpress.org/extend/plugins/option-tree/

  2. htvu
    Member
    Posted 2 years ago #

    Yes, it's easy to do that.
    - Create a template for home page (ex: home-page.php).
    - Create an OptionTree Custom Metabox (see document) for Home page. Before the line of PHP code that register OptionTree Custom Metabox you add some line of code to check if editing page has template name is home-page.php then register metabox otherwise bypass register code. In WP page edit screen choose your homepage template in template select box and save page. Your metabox for home page will show.

  3. FranciscoAMK
    Member
    Posted 2 years ago #

    I did this and worked very well for me. The only problem is that you have to save the post an then the meta box appear.

    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'];
    $template_file = get_post_meta($post_id, '_wp_page_template', TRUE);
    
    if ($template_file == 'template-quienessomos.php') {
        ot_register_meta_box( $quienessomos_meta_box );
    }
  4. htvu
    Member
    Posted 2 years ago #

    If you want to show specific metabox for new post that not save yet, you must regirster all metaboxes in PHP and use JS to show metabox base on what tempate is selected.

  5. Derek Herman
    Member
    Plugin Author

    Posted 2 years ago #

    @FranciscoAMK and @htvu are correct. Currently the code base does not support this feature and you'll need to do one of the two option listed above. Hopefully in the future I'll figure out an elegant way to do this, but I've not come up with one yet.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • OptionTree
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic