What I am trying to do is offer three pages to highlight on the front page. To do this, I would like to offer users a dropdown list of all pages.
I have not worked out how to do this.
I know how to get the pages get_theme_mod( 'mytheme_user_page_1', '' )
is probably about right.
How do I set up the control?
$wp_customize->add_setting( 'mytheme_user_page_1', array(
'default' => ''
) );
$wp_customize->add_control( array(
'type' => 'range',
'section' => 'my_custom_section',
'label' => __( 'Pick a page, bub' ),
// something magical here
) );
Update
I probably did not make this very clear (my bad) I also need to know how to populate the dropdown control. (Or not, see below - I might have missed a trick or two before).
Thanks to a link in the comments and then another link telling me to open my eyes (only far more polite than perhaps I deserved) I did see what was being pointed out. The manual says only this:
- dropdown-pages (use the allow_addition argument to allow users to add new pages from the control)
That's every mention of both terms on the entire page. Maybe I am tired (that is quite likely) but I am struggling to understand how and why this works.
I only found it because I did a text search of the page for "drop" and got 1/1 results. Given the comments does this mean this populates a list of pages? And, if so, what on earth is the allow_addition
argument? (And how do I use it?)
I am starting to suspect that I could chuck a bunch of stuff into my control and hope for the best. Something like this:
'type'=>'dropdown-pages',
'argument'=>'allow_addition', //maybe
'allow_addition'=>TRUE, //possibly
or
'type'=>array('dropdown-pages','allow_addition'), // ?? I'm just guessing
I would prefer to know why I have done it and what is happening here because I will feel obligated to support any themes I release. Responding to a question with, "TBH, I have no idea what I am doing" is not something I want in any possible future.
I apologise if I am being a bit slow today.
I would really appreciate someone taking a few minutes to help me understand. If you could explain the allow_addition
argument while you are at it I will forever be in your debt.
What I am trying to do is offer three pages to highlight on the front page. To do this, I would like to offer users a dropdown list of all pages.
I have not worked out how to do this.
I know how to get the pages get_theme_mod( 'mytheme_user_page_1', '' )
is probably about right.
How do I set up the control?
$wp_customize->add_setting( 'mytheme_user_page_1', array(
'default' => ''
) );
$wp_customize->add_control( array(
'type' => 'range',
'section' => 'my_custom_section',
'label' => __( 'Pick a page, bub' ),
// something magical here
) );
Update
I probably did not make this very clear (my bad) I also need to know how to populate the dropdown control. (Or not, see below - I might have missed a trick or two before).
Thanks to a link in the comments and then another link telling me to open my eyes (only far more polite than perhaps I deserved) I did see what was being pointed out. The manual says only this:
- dropdown-pages (use the allow_addition argument to allow users to add new pages from the control)
That's every mention of both terms on the entire page. Maybe I am tired (that is quite likely) but I am struggling to understand how and why this works.
I only found it because I did a text search of the page for "drop" and got 1/1 results. Given the comments does this mean this populates a list of pages? And, if so, what on earth is the allow_addition
argument? (And how do I use it?)
I am starting to suspect that I could chuck a bunch of stuff into my control and hope for the best. Something like this:
'type'=>'dropdown-pages',
'argument'=>'allow_addition', //maybe
'allow_addition'=>TRUE, //possibly
or
'type'=>array('dropdown-pages','allow_addition'), // ?? I'm just guessing
I would prefer to know why I have done it and what is happening here because I will feel obligated to support any themes I release. Responding to a question with, "TBH, I have no idea what I am doing" is not something I want in any possible future.
I apologise if I am being a bit slow today.
I would really appreciate someone taking a few minutes to help me understand. If you could explain the allow_addition
argument while you are at it I will forever be in your debt.
1 Answer
Reset to default 3To add a Customiser control for selecting a page from a dropdown you just need to set the type
argument to dropdown-pages
:
$wp_customize->add_control( array(
'type' => 'dropdown-pages',
'section' => 'my_custom_section',
'label' => __( 'Pick a page, bub' ),
) );
This will give you a control that's a <select>
dropdown with a list of pages automatically populated. When saved it will save the post ID of the page, or 0
if none is selected.
The 'allow_addition'
argument is an additional argument that can be passed to $wp_customize->add_control()
when using dropdown-pages
that will allow the user to create a page from the Customiser, just like with the settings in the Home page settings section of the Customiser. You would use this argument like this:
$wp_customize->add_control( array(
'type' => 'dropdown-pages',
'allow_addition' => true,
'section' => 'my_custom_section',
'label' => __( 'Pick a page, bub' ),
) );
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745355986a4624119.html
dropdown-pages
is an acceptedtype
for a control. – Jacob Peattie Commented Jul 1, 2019 at 2:20