• Resolved vubon

    (@vubon)


    array(
    ‘id’ => ‘demo_gallery’,
    ‘label’ => __( ‘Gallery’, ‘theme-text-domain’ ),
    ‘desc’ => __( ‘The Gallery option type saves a comma separated list of image attachment IDs. You will need to create a front-end function to display the images in your theme.’, ‘theme-text-domain’ ),
    ‘std’ => ”,
    ‘type’ => ‘gallery’,
    ‘section’ => ‘gallery’,
    ‘rows’ => ”,
    ‘post_type’ => ”,
    ‘taxonomy’ => ”,
    ‘min_max_step’=> ”,
    ‘class’ => ”,
    ‘condition’ => ”,
    ‘operator’ => ‘and’
    ),

    I created a gallery . But I don’t know how to show the gallery on my site. that means which code use for showing the gallery ? please help me .

    https://www.ads-software.com/plugins/option-tree/

Viewing 15 replies - 1 through 15 (of 25 total)
  • Plugin Author Derek Herman

    (@valendesigns)

    Did you created a Gallery option type in your theme options or in a metabox in a post/page?

    Thread Starter vubon

    (@vubon)

    yes I created gallery by above code .

    Plugin Author Derek Herman

    (@valendesigns)

    You didn’t answer my question.

    Thread Starter vubon

    (@vubon)

    sorry I can’t understand your question sir .

    Plugin Author Derek Herman

    (@valendesigns)

    Did you create this gallery in your theme options or as a metabox? They are two different things.

    Thread Starter vubon

    (@vubon)

    Yes I created and upload the photos . Now I want to be show on site the gallery .

    Plugin Author Derek Herman

    (@valendesigns)

    No, you are missing what I’m asking. If you don’t know the difference between theme options and metaboxes I feel like you’re going to have a hard time writing the code required to display the gallery.

    It’s not as simple as creating a gallery and then echoing it out to the screen. You need to know how to write PHP to make it all work. OptionTree creates a way to save the image IDs not display a gallery. You have to write that code yourself. Does that make sense?

    I’m happy to help you but if you are not sure if the gallery is in the theme options or metaboxes it’s going to be hard to help you because they require two different approaches.

    Thread Starter vubon

    (@vubon)

    Thread Starter vubon

    (@vubon)

    Plugin Author Derek Herman

    (@valendesigns)

    It clearly says right above “Theme Options” and that is not a post or page, so you could have just read the title of the administrative page and answered the question. Thanks for the picture.

    Do you have any experience with PHP?

    Derek Herman
    How can i Use Gallery metabox in single.php ?
    Please give me its loop?

    hello Derek Herman !
    You helped lots of people about option tree problems,it’s really grateful.I need a solution like Khurshid Alam says.

    We can upload images through wordpress feature image and use it anywhere with any sizes.But i have a problem.I am using wordpress option tree plugin and I created a meta box which is ‘gallery’ type,i can upload multiple images through it but i can’t get the values with my specific image sizes.I found some codes you had suggested in another thread.But it’s not work for me.The codes you suggested is below:

    In functions.php

    function custom_get_attachment_id( $guid ) {
      global $wpdb;
    
      /* nothing to find return false */
      if ( ! $guid )
        return false;
    
      /* get the ID */
      $id = $wpdb->get_var( $wpdb->prepare(
        "
        SELECT  p.ID
        FROM    $wpdb->posts p
        WHERE   p.guid = %s
                AND p.post_type = %s
        ",
        $guid,
        'attachment'
      ) );
    
      /* the ID was not found, try getting it the expensive WordPress way */
      if ( $id == 0 )
        $id = url_to_postid( $guid );
    
      return $id;
    }

    In theme file

    <?php
    				if ( function_exists( 'ot_get_option' ) ) {
    				$slides = ot_get_option( 'my_slider', array() );
    				if ( ! empty( $slides ) ) {
    					foreach( $slides as $slide ) {
    						$id = custom_get_attachment_id( $slide['image'] );
    						$full_img_src = wp_get_attachment_image_src( $id, 'single-page-slider-img' );
    						$thumb_img_src = wp_get_attachment_image_src( $id, 'single-page-slider-thmub-img' );
    						echo '<div data-thumb="'.$thumb_img_src.'" data-src="'.$full_img_src.'"></div>';
    					}
    				}
    				}
    			?>

    Do i missing something in the above code?Please help me about this.

    Plugin Author Derek Herman

    (@valendesigns)

    @antorjalalin in the future please create your own support request. The gallery option type saves its value as a comma separated list of IDs, unless you’ve added the ot-gallery-shortcode class which converts it to a shortcode. Try the following code to display your images.

    Note: this is untested code written in the browser, but I’m pretty sure it should work.

    if ( function_exists( 'ot_get_option' ) ) {
      $images = explode( ',', ot_get_option( 'my_gallery', '' ) );
      if ( ! empty( $images ) ) {
        foreach( $images as $id ) {
          if ( ! empty( $id ) ) {
            $full_img_src = wp_get_attachment_image_src( $id, 'single-page-slider-img' );
            $thumb_img_src = wp_get_attachment_image_src( $id, 'single-page-slider-thumb-img' );
            echo '<div data-thumb="' . $thumb_img_src . '" data-src="' . $full_img_src . '"></div>';
          }
        }
      }
    }

    Cheers!

    Thank you so much for your reply Mr. Derek Herman ! I will create my own support request in the future also will use your code and let you know in this thread it worked or not.

    Your support is highly appreciated!

    dear Derek Herman
    Unfortunately above codes don’t work for me.I am giving you whole codes whatever i used in my theme.

    I registered meta box fields which are below:

    function custom_meta_boxes() {
    
      $my_meta_box = array(
        'id'          => 'demo_meta_box',
        'title'       => __( 'Theme Informations', 'wpfreeware' ),
        'desc'        => '',
        'pages'       => array( 'post' ),
        'context'     => 'normal',
        'priority'    => 'high',
        'fields'      => array(
          array(
            'label'       => __( 'Theme Promo Description', 'wpfreeware' ),
            'id'          => 'theme_promo',
            'type'        => 'textarea_simple',
    		'desc'        => __( 'Write a attractive description about the theme here for archieve page.Maximum Word length is 18.', 'wpfreeware' ),
    		'rows'        => '5'
          ),
          array(
            'label'       => __( 'Background Css Class / Animation', 'wpfreeware' ),
            'id'          => 'css_classes',
            'type'        => 'text',
    		'desc'        => __( '1. bounceInRight / bounceInLeft <br/> 2. bg1(light blue), bg2(dark blue), bg3(chocolate), bg4(dark gray), bg5(light gray), bg6(orange), bg7(black)', 'wpfreeware' )
          ),
          array(
            'label'       => __( 'Preview Link', 'wpfreeware' ),
            'id'          => 'preview_link',
            'type'        => 'text',
    		'desc'        => __( 'Put the theme preview link here', 'wpfreeware' )
          ),
          array(
            'label'       => __( 'Upload Theme', 'wpfreeware' ),
            'id'          => 'download_file',
            'type'        => 'upload',
    		'desc'        => __( 'Upload the theme file here.', 'wpfreeware' )
          ),
          array(
            'id'          => 'my_slider',
            'label'       => __( 'Theme Screenshots', 'wpfreeware' ),
            'type'        => 'gallery',
    		'desc'        => __( 'Upload this theme screenshots here.', 'wpfreeware' )
          )
        )
        );
    
      if ( function_exists( 'ot_register_meta_box' ) )
        ot_register_meta_box( $my_meta_box );

    The following codes i used in functions.php

    function custom_get_attachment_id( $guid ) {
      global $wpdb;
    
      /* nothing to find return false */
      if ( ! $guid )
        return false;
    
      /* get the ID */
      $id = $wpdb->get_var( $wpdb->prepare(
        "
        SELECT  p.ID
        FROM    $wpdb->posts p
        WHERE   p.guid = %s
                AND p.post_type = %s
        ",
        $guid,
        'attachment'
      ) );
    
      /* the ID was not found, try getting it the expensive WordPress way */
      if ( $id == 0 )
        $id = url_to_postid( $guid );
    
      return $id;
    }

    And last, this piece of codes i used to display the images in slider into single.php .

    <?php
    				if ( function_exists( 'ot_get_option' ) ) {
    				  $images = explode( ',', ot_get_option( 'my_slider', '' ) );
    				  if ( !empty( $images ) ) {
    					foreach( $images as $id ) {
    					  if ( !empty( $id ) ) {
    						$full_img_src = wp_get_attachment_image_src( $id, 'single-page-slider-img' );
    						$thumb_img_src = wp_get_attachment_image_src( $id, 'single-page-slider-thumb-img' );
    						echo '<div data-thumb="' . $thumb_img_src . '" data-src="' . $full_img_src . '"></div>';
    					  }
    					}
    				  }
    				}
    			?>

    Am i missing something? I know PHP basic,I am not expert in PHP.
    Please if you can,give me solution to display the images.
    Thank You!

Viewing 15 replies - 1 through 15 (of 25 total)
  • The topic ‘gallery does not show .’ is closed to new replies.