Hello, I am Brazilian and not dominate the English, I apologize for the bad writing. I have a function with arrays that use the Redux Framework, see below.
function my_get_sidebar_layouts( $inherit = false) {
$layouts = array();
if ( $inherit ) {
$layouts['inherit'] = array( 'title' => __( 'Inherit', THEME_SLUG ), 'img' => IMG_URI . '/images/inherit.png' );
}
$layouts['none'] = array( 'title' => __( 'No sidebar (full width)', THEME_SLUG ), 'img' => IMG_URI . '/images/none.png', 'images_path' => get_template_directory_uri(),);
$layouts['left'] = array( 'title' => __( 'Left sidebar', THEME_SLUG ), 'img' => IMG_URI . '/images/left.png' );
$layouts['right'] = array( 'title' => __( 'Right sidebar', THEME_SLUG ), 'img' => IMG_URI . '/images/right.png' );
return $layouts;
}
I use this way in redux:
array(
'id' => 'archive_sidebar',
'type' => 'image_select',
'title' => __( 'Sidebar layout', THEME_SLUG ),
'subtitle' => __( 'Choose sidebar layout for archive templates', THEME_SLUG ),
'options' => ny_get_sidebar_layouts(),
'default' => 'right'
),
it works perfect…
A few days ago I’m trying to use it the same way in CMB2 with CMB2-radio-image-master. But I can not. Only the value goes, but the image and the title does not. can anybody help me?
How do I use this function in CMB2 fields in the same way that I use in Redux?
$cmb_demo->add_field( array(
'name' => __( 'Test Radio Image', 'cmb2' ),
'desc' => __( 'field description (optional)', 'cmb2' ),
'id' => $prefix . 'radioimg',
'type' => 'radio_image',
'options' => array(
'full-width' => __('Full Width', 'cmb2'),
'sidebar-left' => __('Left Sidebar', 'cmb2'),
'sidebar-right' => __('Right Sidebar', 'cmb2'),
),
'images_path' => get_template_directory_uri(),
'images' => array(
'full-width' => 'images/content_no_sid.png',
'sidebar-left' => 'images/content_sid_left.png',
'sidebar-right' => 'images/content_sid_right.png',
)
) );
Honestly, I think you're going to want to nudge https://github.com/satwinderrathore/CMB2-radio-image about that, as that's not an addon that WebDevStudios maintains at all. We're not going to be super familiar with it.
Chances are you will need to fill in the same required fields somehow, if you're not already doing so.
@tw2113 Thanks for answering. Yes, I'm already using CMB2-radio-image. I just wish I could use it with arrays within a function, not need to put everything again. If I could extract the arrays within that function and place in the fields, would be great. But I can not do that, would have to make a kind of loop with the values extracted into the CMB2 fields. Discover the CMB2 a few days ago and it really blew my mind ...;)
@tw2113 Is there a tutorial which teaches to create my own fields? I would try it. I believe in creating a field radio native image, similar to redux that extracts the function of arrays with title and image.
Personally, I'd probably end up looking more at breaking up that my_get_sidebar_layouts function to be a bit more modular, but that's just me. I'm curious what could be done with wp_list_pluck() and some minor refactoring of the my_get_sidebar_layouts() function
There is https://github.com/WebDevStudios/CMB2/wiki/Adding-your-own-field-types available for a tutorial of sorts from our wiki, may prove useful.
@tw2113 Thank you! Your way, how do you build this my get_sidebar _layouts?
I don't have an answer for that part, all I had was some suggestions to explore.
Going to close this as an open issue, as it's not a bug with CMB2, but comments aren't disabled because of that, for what it's worth.
@tw2113 I appreciate your answers. They are helping me a lot. I was just being abused, looking for an easy way to do this with my last question. I apologize. Thank you.
No worries, by any means.