File list of option page do not display in frontend
-
Hello everyone! How are you?
I always use cmb2 and I never had problems.
The times I used a file list … I did it in a CPT. This time I need to do it in an option page.
I manage to create the metabox in the backend and load the files and that they are saved there.My problem is when I want to show them in the frontend.
I paste my code, which works correctly in the CPT. So they tell me where I’m wrong if they’re so kind.
Backend:
// Slider página principal $home_options->add_field( array( 'name' => 'Slider página principal', 'desc' => 'Agrega las imagenes del slider', 'id' => 'slider-principal-fox', 'type' => 'file_list', 'preview_size' => array( 100, 100 ), // Default: array( 50, 50 ) 'query_args' => array( 'type' => 'image' ), // Only images attachment // Optional, override default text strings 'text' => array( 'add_upload_files_text' => 'Añadir o Subir Imagen', // default: "Add or Upload Files" 'remove_image_text' => 'Eliminar Imagen', // default: "Remove Image" 'file_text' => 'Imagen:', // default: "File:" 'file_download_text' => 'Descargar', // default: "Download" 'remove_text' => 'Eliminar', // default: "Remove" ), ) );
—
Frontend:
/** * Sample template tag function for outputting a cmb2 file_list * * @param string $file_list_meta_key The field meta key. ('wiki_test_file_list') * @param string $img_size Size of image to show */ function cmb2_output_file_list( $file_list_meta_key, $img_size = 'large' ) { // Get the list of files $files = get_post_meta( get_the_ID(), $file_list_meta_key, 1 ); // Loop through them and output an image foreach ( (array) $files as $attachment_id => $attachment_url ) { echo '<figure>'; echo wp_get_attachment_image( $attachment_id, $img_size ); echo '</figure>'; } } cmb2_output_file_list( 'slider-principal-fox', 'large' );
Thanks in advance.
Regards!
The page I need help with: [log in to see the link]
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘File list of option page do not display in frontend’ is closed to new replies.