Viewing 8 reply threads
  • Author
    Posts
    • #6549
      bicho44
      Member

      Hi:

      I found this topic [Resolved]Metabox/Post Type Only Specific Assets where they teach how to add assets to a specific page template.
      I need to do something similar but with a meta box or a field outside metabox if someone select a page template, i need a field under the container editor, so i can put a shortcode or whatever.
      Any directions will be great.
      Thanks in advance.

    • #6555
      Steve
      Keymaster

      @bicho44– Sorry, I’m not clear on your request. Can you provide details, or screenshots?

    • #6559
      bicho44
      Member

      @steve

      I send you a picture, but is really simple, when i select especific template page in page attributes, that page need a attribute, in this case a shortcode, so i need to show the text field.
      I manage to extend the page attribute metabox and put in there a show / hide radio button to show the text field, but that makes the shorcode field avaliable to a templates where is no need it.

      Regards and thanks.

      Attachments:
      You must be logged in to view attached files.
    • #6564
      Steve
      Keymaster

      You can use the TEMPLATE parameter for meta-boxes.

    • #6565
      bicho44
      Member

      Thanks, @steve works like a charm.

      One nice addition will be the Page Template dropdown work’s like a show / hide field so you dont have to save first the page to the field be showed 😀

      I know im a pusher, im sorry 😛

      Regards and really thanks

    • #6569
      Steve
      Keymaster

      @bicho44– That requires a little javascript and is on the feature list. We appreciate your pushing. 😉

    • #6570
      Steve
      Keymaster

      @bicho44– You can also use a little jquery to hide the field. This code will HIDE the field, which means it is still rendered and will save data. So make sure you set a default value and check for it in your code.

      Here’s a quick way of doing it:
      1) Wrap your radio field in a div. For example:

      <div id="radio-hide">
      <?php
      piklist('field', array(
        'type' => 'radio'
        ,'field' => 'radio_choice'
        ,'label' => 'Please choose',
        ,'value' => 'no' // sets default value
        ,'choices' => array(
          'yes' => 'Yes'
          ,'no' => 'No'
        )
      ));
      ?>
      </div>
      

      2) Then add some jquery under that:

      <script>
      jQuery(document).ready(function( $ ) {
       $('select').on('change', function() {
        if(this.value == 'page-templates/front-page.php') {
         $( "#radio-hide" ).hide();
        }
        else {
         $( "#radio-hide" ).show();
        }
       })
      });
      </script>

      Change page-templates/front-page.php to the page template you want.

    • #6576
      bicho44
      Member

      @steve:

      Thanks, i was thinking in a similar solution, but trying to piklistplicate (replicate the piklist way 😉 ) the template page dropdown with a show / hide option.

      But your solution is nice and much more simplier.

      Thanks again

    • #6577
      Steve
      Keymaster

      One of the best parts of Piklist, is that you don’t have to do everything the Piklist way… you can mix in standard PHP and jQuery.

      Closing ticket

Viewing 8 reply threads
  • The topic ‘How to show a field if a template page is selected’ is closed to new replies.