- This topic has 8 replies, 2 voices, and was last updated 5 years, 8 months ago by
Steve.
-
AuthorPosts
-
-
May 27, 2016 at 1:00 pm #6549
bicho44MemberHi:
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. -
June 2, 2016 at 11:06 am #6555
-
June 2, 2016 at 11:50 am #6559
bicho44Member@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. -
June 2, 2016 at 12:50 pm #6564
-
June 2, 2016 at 3:32 pm #6565
bicho44MemberThanks, @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
-
June 2, 2016 at 9:45 pm #6569
-
June 2, 2016 at 10:07 pm #6570
SteveKeymaster@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.phpto the page template you want. -
June 3, 2016 at 11:31 am #6576
bicho44Member@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
-
June 3, 2016 at 11:35 am #6577
SteveKeymasterOne 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
-
-
AuthorPosts
- The topic ‘How to show a field if a template page is selected’ is closed to new replies.