Tagged: , ,

Viewing 3 reply threads
  • Author
    Posts
    • #4202
      upside
      Member

      I’m working on creating a widget that will have a photo and some text and a title. I’ve set-up the fields like so:

      <?php
      /*
      Width: 420
      */
      
      piklist('field', array(
          'type' => 'text'
          ,'field' => 'tc_widget_title'
          ,'label' => 'Text'
          ,'value' => ''
          ,'help' => 'add the title of the widget area here i.e. Guild Quality or Houzz'
          ,'attributes' => array(
            'class' => 'regular-text'
          )
        ));
      
        piklist('field', array(
          'type' => 'textarea'
          ,'field' => 'tc_widget_text_area'
          ,'label' => 'Large Code'
          ,'description' => 'class="large-text code" rows="10" columns="50"'
          ,'value' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'
          ,'attributes' => array(
            'rows' => 10
            ,'cols' => 50
            ,'class' => 'large-text code'
          )
       
        ));
      
        piklist('field', array(
          'type' => 'file'
          ,'field' => 'tc_logo_widget'
          ,'label' => __('Add File(s)','piklist-demo')
          ,'description' => __('This is the uploader seen in the admin by default.', 'piklist-demo')
          ,'options' => array(
            'modal_title' => __('Add File(s)', 'piklist-demo')
            ,'button' => __('Add', 'piklist-demo')
          )
          ,'validate' => array(
            array(
              'type' => 'limit'
              ,'options' => array(
                'min' => 0
                ,'max' => 2
              )
            )
          )
        ));
      

      Following the user guide I’ve set-up the display like so

      <?php
      /*  
      Title: Testimonials
      */
      ?>
      
      <?php echo $before_widget; ?>
      
        <?php echo $before_title; ?>
      
        <?php echo $settings['tc_widget_title']; ?>!
        
        <?php echo $after_title; ?>
      
        <?php echo $settings['tc_widget_text_area']; ?>!
      
        <?php echo $settings['tc_logo_widget']; ?>!
      
          
      <?php echo $after_widget; ?>
      

      I’m getting an undefined index error for the upload field. Is there some added trick for displaying image fields on the front-end?

      Thanks for your help!

    • #4203
      Steve
      Keymaster

      Since you can upload multiple files, the file upload file stores multiple image IDs in an array. You’re getting an error because you’re trying to echo out an array.

      You need to pull the image IDs and then get the url. This doc gives a good explanation >

      Here’s how to display the images you uploaded:

      <?php $image_ids = $settings['tc_logo_widget']; // Get all the IDs?>
        <?php foreach ($image_ids as $image) : // Loop through all the IDs ?>
          <img src="<?php echo wp_get_attachment_url($image);?>" />
        <?php endforeach; ?>
      
    • #4235
      upside
      Member

      Hey Steve,

      That makes complete sense. I knew I was missing something pretty basic. You guys rock and Piklist is so awesome. I’ve been using it for over a year now and I’m just starting to realize how powerful it can be!

      Thanks Again. You can mark this as resolved.

      Best,
      Tyler

    • #4236
      Steve
      Keymaster

      Hey Tyler– Glad to help! If you have a minute, please tell the world how much you love Piklist by leaving a 5 Star review on WordPress.org.

      Closing this ticket.

Viewing 3 reply threads
  • The topic ‘displaying widget upload field front-end’ is closed to new replies.