- This topic has 3 replies, 2 voices, and was last updated 5 years, 4 months ago by
jrcreative.
-
AuthorPosts
-
-
October 11, 2016 at 12:06 am #7423
kenwalkerParticipantGood day, I would like some assistance on outputting uploaded images to the front-end of my website.
Currently I made a settings page based on the docs.
Here is my code:(functions.php)add_filter('piklist_admin_pages', 'piklist_theme_setting_pages'); function piklist_theme_setting_pages($pages) { $pages[] = array( 'page_title' => __('Custom Settings') ,'menu_title' => __('Settings', 'piklist') ,'sub_menu' => 'themes.php' //Under Appearance menu ,'capability' => 'manage_options' ,'menu_slug' => 'custom_settings' ,'setting' => 'my_theme_settings' ,'menu_icon' => plugins_url('piklist/parts/img/piklist-icon.png') ,'page_icon' => plugins_url('piklist/parts/img/piklist-page-icon-32.png') ,'single_line' => true ,'default_tab' => 'Basic' ,'save_text' => 'Save Demo Settings' ); return $pages; }Then I made metaboxes for the settings page:(demo-settings.php)
/* Title: Theme Settings Section Setting: my_theme_settings */ piklist('field', array( 'type' => 'group' ,'field' => 'slides_basic' ,'add_more' => true ,'label' => __('Slide Images with Basic uploader', 'my_theme_settings') ,'description' => __('This is the same field as above, except it is using the Basic uploader.', 'piklist-demo') ,'fields' => array( array( 'type' => 'file' ,'field' => 'image' ,'label' => __('Slides', 'piklist-demo') ,'columns' => 12 ,'options' => array( 'modal_title' => __('Add File(s)', 'my_theme_settings') ,'button' => __('Add', 'piklist-demo') ) ,'validate' => array( array( 'type' => 'image' ) ) ) ,array( 'type' => 'text' ,'field' => 'url' ,'label' => __('URL', 'my_theme_settings') ,'columns' => 12 ) ) ));Now I wanted to display my uploaded images on my website.
My display code:<?php $settings = get_option('my_theme_settings'); $image_up = $settings['slides_basic']; // Get all the IDs print_r($image_up); $image_ids = $image_up[image]; // Get all the IDs $image_ids = count($image_ids)-1; ?> <?php foreach ($image_ids as $image) : // Loop through all the IDs ?> <img src="<?php echo wp_get_attachment_url($image);?>" /> <?php endforeach; ?>ok, now using the “print_r” I got the list of arrays:
Array ( [0] => Array ( [image] => Array ( [0] => 34 ) [url] => sample URL ) [1] => Array ( [image] => Array ( [0] => 35 ) [url] => sample URL2 ) )Then here comes the problem. I’m not sure on how to display my images and the url.
Currently As shown above I got an error when trying to display my images:Warning: Invalid argument supplied for foreach()Any advise and thoughts will be very much appreciated.
-
October 11, 2016 at 6:49 pm #7427
jrcreativeMember$image_ids = $image_up[image]; // Get all the IDs
This line doesn’t get all of the ids like you’re expecting. Based on the result of your ‘print_r’ $image_up[image] doesn’t exist.
And you’re wiping out your image_ids array with this line:
$image_ids = count($image_ids)-1;From the results of your
print_rit looks like maybe you’ve tried this a couple of different ways and have some mixed up meta stored in the options table. Here’s a cleaned up version of the meta box to get you started.<?php /* Title: Theme Settings Section Setting: my_theme_settings */ piklist('field', array( 'type' => 'group' ,'field' => 'slides_basic' ,'add_more' => true ,'label' => __('Slide Images with Basic uploader') ,'description' => __('Basic uploader') ,'fields' => array( array( 'type' => 'file' ,'field' => 'image' ,'label' => __('Slides') ,'columns' => 12 ,'options' => array( 'modal_title' => __('Add File(s)') ,'button' => __('Add') ) ) ,array( 'type' => 'text' ,'field' => 'url' ,'label' => __('URL') ,'columns' => 12 ) ) )); ?> -
October 12, 2016 at 3:42 am #7428
kenwalkerParticipantThank you for the response Sir. And yes you are correct that I tried different approaches for this matter.
I think my lack of knowledge in outputting multi array and using piklist that resulted to this problem.
I’m currently still experimenting on this.
Will it be alright if you could help me with tips or advise on the correct way of outputting a multi array, just to pull me back on the right track. I think I’m currently derailing on the track. 🙂
thanks.
-
October 12, 2016 at 2:33 pm #7429
jrcreativeMemberI don’t mind helping at all, however, working with multi-dimensional arrays might be too generic a topic for this forum. Stack overflow or the documentation at php.net might be a better fit. Post any Piklist questions here, though!
-
-
AuthorPosts
- You must be logged in to reply to this topic.