Tagged: ,

Viewing 4 reply threads
  • Author
    Posts
    • #1889
      civilz
      Member

      hi
      i use this code in setting section :

      piklist('field', array(
          'type' => 'file'
          ,'field' => 'logo_upload_file'
          ,'scope' => 'post_meta'
          ,'label' => 'plz upload logo'
          ,'description' => 'Size Only : 97 x 338 px'
          ,'options' => array(
            'basic' => true
          )
        ));

      and use this theme :

      <a href="#"><img class="head-logo" src="<?php bloginfo('template_directory'); ?/images/logo.jpg"></a>

      i want set the upload img url on the :
      src="<?php bloginfo('template_directory'); ?>/images/logo.jpg">

      how to set?

    • #1890
      civilz
      Member
    • #1892
      Steve
      Keymaster

      @civilz

      1) Since this is a setting, let’s grab all your settings: $settings = get_option('my_settings'); . Replace my_settings with whatever is in the comment block of your settings file.
      2) Now let’s find the image ID for the field logo_upload_file: $image_id = $settings['logo_upload_file'];
      3) WordPress gave us back an array, but we are only interested in the first key=>value pair: $image_id = $image_id[0];
      4) Now that we have the image ID for the attachment, lets use a standard WordPress function to display the associated image: <a href="#"><img class="head-logo" src="<?php echo wp_get_attachment_url($image_id);?>"></a>

      FULL CODE

      $settings = get_option('my_settings');
      $image_id = $settings['logo_upload_file'];
      $image_id = $image_id[0];

      <a href="#"><img class="head-logo" src="<?php echo wp_get_attachment_url($image_id);?>"></a>

      Let me know if you still have any issues.

    • #1897
      civilz
      Member

      thanks but not work !

      my code :
      theme code :

      
      <?php 
      $settings = get_option('my_theme_settings');
      $image_id = $settings['logo_upload_file'];
      $image_id = $image_id[0];
      ?>
      <a href="#"><img class="head-logo" src="<?php echo wp_get_attachment_url($image_id); ?>"></a>
      

      themesetting code :

      
      *
       Title: setting
       Setting: my_theme_settings
       */
      
      /*---LOGO---*/
      piklist('field', array(
          'type' => 'file'
          ,'field' => 'logo_upload_file'
          ,'scope' => 'post_meta'
          ,'label' => 'logo upload'
          ,'description' => 'Size Only : 97 x 338 px'
          ,'options' => array(
            'basic' => true
          )
        ));
      

      but nothing display !

    • #1898
      Steve
      Keymaster

      @civilz– I believe this is not working because you are on a settings page and setting: 'scope' => 'post_meta'.

      Let Piklist determine the scope automagically:

      piklist('field', array(
          'type' => 'file'
          ,'field' => 'logo_upload_file'
          ,'label' => 'logo upload'
          ,'description' => 'Size Only : 97 x 338 px'
          ,'options' => array(
            'basic' => true
          )
        ));
      
Viewing 4 reply threads
  • The topic ‘displaying images upload field problem!!!’ is closed to new replies.