• Resolved miruru

    (@miruru)


    First of all, fantastic plugin, works like a charm.

    Anyway, my question is, using the do_shortcode() function, how would I set it up for the tabs? I’ve tried this but it seems to append the [/gn_tab][/gn_tabs] after the text of my content.

    This is what I have:

    <?php echo do_shortcode( '[gn_tabs]' ) ?>
    <?php echo do_shortcode( '[gn_tab title="content title"]' ) ?>
    <?php echo do_shortcode( 'shortcode to my content' ) ?>
    <?php echo do_shortcode( '[/gn_tab]' ) ?>
    <?php echo do_shortcode( '[/gn_tabs]' ) ?>

    I’ve tested using the other shortcodes and they work find, i.e. displaying the bloginfo.

    Any help would be most appreciated. Once again thank you for a fantastic plugin!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter miruru

    (@miruru)

    After posting my query, I started playing around and have managed to work this out but only for a single tab. I entered the shortcodes for the tabs in one do_shortcodecommand rather than split them up:

    <?php echo do_shortcode( '[gn_tabs][gn_tab title="TEST"][SHORTCODE FOR CONTENT][/gn_tab][/gn_tabs]' ) ?>

    How would this work if I have multiple tabs? As it still only display one tab.

    Plugin Author Vova

    (@gn_themes)

    Try this:

    <?php
    $my_tabs = '
    [gn_tabs]
       [gn_tab title="TEST"] Some content [/gn_tab]
       [gn_tab title="TEST"] Some content [/gn_tab]
       [gn_tab title="TEST"] Some content [/gn_tab]
    [/gn_tabs]
    ';
    echo do_shortcode( $my_tabs );
    ?>
    Thread Starter miruru

    (@miruru)

    thank you. That worked perfectly!!!

    Another quick question re the above code.

    How would I use the IF / ELSE statement with the above code? The content is displayed in a custom field.

    For example:

    1. Tab A and Tab B will always be displayed.
    2. If not empty, display Tab C, however do not display.
    3. If not empty, display Tab D, however do not display.

    Is this possible?

    Thank you again for a great plugin!

    Plugin Author Vova

    (@gn_themes)

    You just need to create complete code in variable before do_shortcode execution.
    Example:

    $return = '[gn_tabs]';
    $return .= '[gn_tab title="..."] TAB A [/gn_tab]';
    $return .= '[gn_tab title="..."] TAB B [/gn_tab]';
    
    if ( !empty( $c ) ) {
       $return .= '[gn_tab title="..."] TAB C [/gn_tab]';
    }
    
    $return .= '[/gn_tabs]';
    
    // Now, variable has complete code, and we can execute it
    
    echo do_shortcode( $return );
    Thread Starter miruru

    (@miruru)

    Hu gn_themes, thank you for the speedy response.

    I’ve tried the following:

    <?php
    
    $return .= '[gn_tabs style="2"]';
    $return .= '[gn_tab title="table"] [table] [/gn_tab]';
    $return .= '[gn_tab title="field1"] [field1] [/gn_tab]';
    
    if ( !empty( $c ) ) {
       $return .= '	[gn_tab title="field2"][field2"][/gn_tab]';
    }
    
    if ( !empty( $c ) ) {
       $return .= '	[gn_tab title="field3"][field3][/gn_tab]';
    }
    
    $return .= '[/gn_tabs]';
    
    // Now, variable has complete code, and we can execute it
    echo do_shortcode( $return );
    ?>

    However this only displayed the first tab only. I’m not sure what i’m doing wrong. I’m not PHP efficient but I am learning. Any help would be most appreciated.

    Plugin Author Vova

    (@gn_themes)

    wrong: $return .= '[gn_tabs style="2"]'; – stray dot
    right: $return = '[gn_tabs style="2"]';

    wrong:

    if ( !empty( $c ) ) {
       $return .= '	[gn_tab title="field2"][field2"][/gn_tab]';
    }

    – stray quotes
    right:

    if ( !empty( $c ) ) {
       $return .= '	[gn_tab title="field2"][field2][/gn_tab]';
    }

    And don’t forget to specify $c

    Double check you code, before testing.

    Thread Starter miruru

    (@miruru)

    Thank you again for speedy response.

    Also thank you for pointing out the stray . and quotes, they have been removed.

    I have now managed to get this working with the following:

    <?php
    $return = '[gn_tabs style="2"]';
    $return .= '[gn_tab title="table"] [table] [/gn_tab]';
    
    if ( fs_get_meta('field1') !== ''  ) {
       $return .= ' [gn_tab title="field1"][field1][/gn_tab] ';
    }
    if ( fs_get_meta('field2') !== ''  ) {
       $return .= '	[gn_tab title="field2"][field2][/gn_tab]';
    }
    if ( fs_get_meta('field3') !== ''  ) {
       $return .= '	[gn_tab title="field3"][field3][/gn_tab]';
    }
    
    $return .= '[/gn_tabs]';
    
    // Now, variable has complete code, and we can execute it
    echo do_shortcode( $return );
    ?>

    Thank you for this fantastic plugin.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Plugin: Shortcodes Ultimate] Using shortcode in theme’ is closed to new replies.