2016-04-22 6 views
0

Ich muss einen der Shortcodes meines Themas ändern, so dass ich eine Klassen-ID an die Spalten übergeben kann. Ich muss in der Lage sein, einen zusätzlichen Parameter id="" zu setzen und dann eine beliebige ID einzugeben.Wie ID in Shortcode übergeben - WordPress

Dies sind die Kurzwahlnummern:

if (!function_exists('two_col_50_50_col1')) { 
    function two_col_50_50_col1($atts, $content = null) { 
     return '<div class="two_columns_50_50 clearfix"><div class="column1"><div class="column_inner">' . do_shortcode($content) . '</div></div>'; 
    } 
} 
add_shortcode('two_col_50_50_col1', 'two_col_50_50_col1'); 

if (!function_exists('two_col_50_50_col2')) { 
    function two_col_50_50_col2($atts, $content = null) { 
     return '<div class="column2"><div class="column_inner">' . do_shortcode($content) . '</div></div></div>'; 
    } 
} 
add_shortcode('two_col_50_50_col2', 'two_col_50_50_col2'); 

Antwort

0

Sie Argumente zu Kurzwahlnummern wie dies passieren kann:

// [bartag foo="foo-value"] 
function bartag_func($atts) { 
$a = shortcode_atts(array(
    'foo' => 'something', 
    'bar' => 'something else', 
), $atts); 

return "foo = {$a['foo']}"; 
} 
add_shortcode('bartag', 'bartag_func'); 

Also für Ihren Code, es wäre wie:

if (!function_exists('two_col_50_50_col1')) { 
function two_col_50_50_col1($atts, $content = null) { 
$a = shortcode_atts(array(
    'id' => '' 
), $atts); 
return '<div class="two_columns_50_50 clearfix '.$a['id'].'"><div   
class="column1"><div class="column_inner">' . do_shortcode($content) . '</div></div>'; 
} 
    } 
add_shortcode('two_col_50_50_col1', 'two_col_50_50_col1'); 

if (!function_exists('two_col_50_50_col2')) { 
function two_col_50_50_col2($atts, $content = null) { 
    $a = shortcode_atts(array(
    'id' => '' 
), $atts); 
    return '<div class="column2 '.$a['id'].'"><div class="column_inner">' .  do_shortcode($content) . '</div></div></div>'; 
} 
} 
add_shortcode('two_col_50_50_col2', 'two_col_50_50_col2'); 

Und Sie kann den Shortcode anrufen wie:

[two_col_50_50_col2 id="something"] 

Ausführliche Informationen über Wordpress Shortcodes lesen Sie diese Dokumentation: https://codex.wordpress.org/Shortcode_API

+0

gut er die ID in der Klasse Attribut wollte. Also habe ich den Wert von ID '$ a ['id']' im Klassenattribut des ersten HTML-Elements hinzugefügt. –