0

I am a new to php and would like to know how insert multiple shortcodes with shortcodes

the desired result would look something like this

[logo_section_2 section-title="1" section-title-text="WE SHARE THE SAME CULTURE" logos-second-row="true"]
  [logo_images logo-id="1" logo-image-source="http://localhost:8888/signal-theme-export/wordpress/wp-content/uploads/2016/07/logo-swiss.png"]
  [logo_images logo-id="2" logo-image-source="http://localhost:8888/signal-theme-export/wordpress/wp-content/uploads/2016/07/logo-hudson.png"]
  [logo_images logo-id="3" logo-image-source="http://localhost:8888/signal-theme-export/wordpress/wp-content/uploads/2016/07/logo-twitter.png"]
  [logo_images logo-id="4" logo-image-source="http://localhost:8888/signal-theme-export/wordpress/wp-content/uploads/2016/07/logo-index.png"]
  [logo_images logo-id="5" logo-image-source="http://localhost:8888/signal-theme-export/wordpress/wp-content/uploads/2016/07/logo-reed.png"]
  [logo_images logo-id="6" logo-image-source="http://localhost:8888/signal-theme-export/wordpress/wp-content/uploads/2016/07/logo-viagogo.png"]

  [logo_images_2 logo-id="4" logo-image-source="http://localhost:8888/signal-theme-export/wordpress/wp-content/uploads/2016/07/logo-index.png"]
  [logo_images_2 logo-id="5" logo-image-source="http://localhost:8888/signal-theme-export/wordpress/wp-content/uploads/2016/07/logo-reed.png"]
  [logo_images_2 logo-id="6" logo-image-source="http://localhost:8888/signal-theme-export/wordpress/wp-content/uploads/2016/07/logo-viagogo.png"]

[/logo_section_2]

This is so I can add multiple rows of images

my php is as below

<?php

add_shortcode('logo_section_2', 'logo_section_2'); function logo_section_2( $atts, $content = "" ) { shortcode_atts( array( 'section-title' => false, 'section-title-text' => '', 'logos-second-row' => false, // ..... ),$atts);

    $output = '';
    $output .= '<div class="logo-section clearfix">';   
      $output .= '<div class="logo-section--inner clearfix">'; 
          if ($atts['section-title'] == true) {
          $output .= '<h2 class="heading--small heading--bold heading--uppercase heading--sans-serif heading--center heading">'. $atts['section-title-text'] .'</h2>';
          } else {
                  $output .= '';
          }

          $output .=  '<div class="logo-section--row clearfix">' . do_shortcode($content) . '</div>';

          if ($atts['logos-second-row'] == 'true') {
            $output .=  '<div class="logo-section--row clearfix">' . do_shortcode($content) . '</div>';
          } else {
                  $output .= '';
          }
      $output .= '</div>'; 
    $output .= '</div>';
  return $output;

}

add_shortcode('logo_images', 'logo_images');
function logo_images($atts){
  shortcode_atts(
    array(
      'logo-id' => '',
      'logo-image-source' => '',
      'logo-alt' => '',
    ),$atts);
    $output = '';
    if($atts['logo-id'] || $atts['logo-image-source']){
               $output .= '<img class="logo-'.$atts['logo-id'].'" src="' . $atts['logo-image-source'] . '" alt="" />';
    } else {
            $output .= '';
    }
    return $output;
 }
add_shortcode('logo_images_2', 'logo_images_2');
function logo_images_2($atts){
  shortcode_atts(
    array(
      'logo-id' => '',
      'logo-image-source' => '',
      'logo-alt' => '',
    ),$atts);
    $output = '';
    if($atts['logo-id'] || $atts['logo-image-source']){
               $output .= '<img class="logo-'.$atts['logo-id'].'" src="' . $atts['logo-image-source'] . '" alt="" />';
    } else {
            $output .= '';
    }
    return $output;
 }

any help would be awesome!

1
  • This looks too static code ! Commented Jul 4, 2016 at 11:31

1 Answer 1

0

I think what you're asking is about nested shortcodes... you want to trigger a UI element that may have one or more (variable number) internal items.

This concept is difficult to explain because it requires several code concepts put together. But I will try:

  1. Outer Shortcode:

    a. Set a global to test if already in that shortcode

    b. call do_shortcode($content) to execute inner shortcodes

    c. (Inner shortcode will set up an global array)

    d. Generate full UI using a loop on the global array

    e. return the output

  2. Inner Shortcode:

    a. set up a global array to be used by the outer shortcode

    b. generate the content and place the output in an array item

    c. return blank/no output

It's not that straight forward tho... you'll need to consider multiple outer shortcode calls, incorrectly nested shortcodes, and if you want or don't want non-shortcode in the inner layer to be processed or not.

Have a look at this code... maybe you can extract some ideas from it.

Sign up to request clarification or add additional context in comments.

1 Comment

( Link fixed. )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.