Support » Plugin: OptionTree » Slider Loop Array

  • Resolved sam.skirrow


    I know this is in the documentation, but can anyone talk me through in a bit ore detail how to create a slider loop array?

    What I’m struggling with is to understand what Sections and Settings to add and what ID etc do I need to give these?

    I currently have this code:

        <div id="my-carousel">
    if ( function_exists( 'ot_get_option' ) ) {
      /* get the slider array */
      $slides = ot_get_option( 'my_slider', array() );
      if ( ! empty( $slides ) ) {
        foreach( $slides as $slide ) {
          echo '
            <img src="' . $slide['image'] . '" /></a>

    and I have a section called Slider with an ID of home_slider, in that section is a list-item Setting with the label Slider and ID of my_slider

    Thanks in advance,

Viewing 1 replies (of 1 total)
  • Plugin Author Derek Herman


    Than this code should already work for you as the option you’re trying to get data for is actually my_slider.

    This part get’s the array of slides.

    $slides = ot_get_option( 'my_slider', array() );

    The part below checks that the array is not empty and loops over it to echo out a unordered list of images. Depending on what settings are in your list item the array keys may not be the same. You’ll need to do a print_r($slides); to find out what your array keys are. For example, the $slide['image'] above is asking for the value of an item in the array that has a key of “image”.

Viewing 1 replies (of 1 total)
  • The topic ‘Slider Loop Array’ is closed to new replies.