codepress / column-shortcodes

Column Shortcodes for WordPress
https://wordpress.org/plugins/column-shortcodes/
15 stars 17 forks source link

free floating colums and block shortcodes #20

Open szepeviktor opened 10 years ago

szepeviktor commented 10 years ago

Could I add shortcodes for "width-less" div-s?

Just floating left or right.

szepeviktor commented 10 years ago

Thank you for your plugin! Just made a landing page: http://www.prezimagyarul.hu/roadshow/

Sometimes also a very plain "empty" shortcode is very useful, which displays only a <div> with the all of the attributes of the shortcode like

[block class="bigpink" style="position: absolute"]
Content ....
[block2 anyattribute="anyvalue"]
(image here)
[/block2]
[/block]

Please consider adding [block], [block2] ... [block9]

szepeviktor commented 10 years ago

I think WordPress does not allow of nesting the same shortcode like

[scode]
[scode]
Content....
[/scode]
[/scode]

So we need numbered blocks.

szepeviktor commented 9 years ago
function print_tag( $tag, $attributes = array(), $content = null ) {

    if ( empty( $tag ) || ! is_array( $attributes ) )
        return '';

    foreach ( $attributes as $attribute => &$data ) {
        if ( empty( $data ) || true === $data ) {
            // empty attributes
            $data = esc_attr( $attribute );
        } else {
            $data = implode( ' ', (array) $data );
            $data = $attribute . '="' . esc_attr( $data ) . '"';
        }
    }

    $attribute_string =  $attributes ? ' ' . implode( ' ', $attributes ) : '';
    $html = '<' . $tag . $attribute_string;
    $html .= is_null( $content ) ? ' />' : '>' . $content . '</' . $tag . '>';
    return wp_kses_post( $html );
}
szepeviktor commented 9 years ago

and

function empty_block_shortcode( $atts, $content = '' ) {
    return print_tag( 'div', $atts, $content );
}
add_shortcode( 'block', 'empty_block_shortcode' );
add_shortcode( 'block2', 'empty_block_shortcode' );
add_shortcode( 'block3', 'empty_block_shortcode' );
add_shortcode( 'block4', 'empty_block_shortcode' );
add_shortcode( 'block5', 'empty_block_shortcode' );
add_shortcode( 'block6', 'empty_block_shortcode' );
add_shortcode( 'block7', 'empty_block_shortcode' );
add_shortcode( 'block8', 'empty_block_shortcode' );
add_shortcode( 'block9', 'empty_block_shortcode' );