0
我想添加一個簡碼在wordpress內容中設置網格。我的主題基於foundation5所以我創建了一個名爲「Shortcodes.php」的新文件並將其加載到functions.php中。我插入下面的代碼到簡碼文件動態行簡稱爲wordpress
<?php
function spalten_zeilen_function($atts, $content = null) {
extract(shortcode_atts(array(
'width' => '',
'position' => '',
'vertical' => '',
), $atts));
if ($position == 'first') {
$return_string = '<div class="row '.$vertical.'">';
}
$return_string = '<div class="small-'.$width.' columns '.$position.';">';
$return_string = do_shortcode($content);
$return_string .= '</div>';
if ($position == 'end') {
$return_string = '</div>';
}
wp_reset_query();
return $return_string;
}
function register_shortcodes(){
add_shortcode('grid_shortcode', 'spalten_zeilen_function');
}
add_action('init', 'register_shortcodes');
add_filter('widget_text', 'do_shortcode'); // Shortcodes auch in Widgets ausführen
add_filter('comment_text', 'do_shortcode'); // Shortcodes auch in den Kommentaren ausführen
add_filter('the_excerpt', 'do_shortcode'); // Shortcodes auch in den Excerpts ausführen
?>
所以我想要做的是,如果短碼處理第一內容打開一個新行。 之後我想設置列的寬度,如果短代碼處理最後一個內容的結束標記。之後,內容本身跟隨,如果它是最後一個內容,則緊隨該行的結束div。
呈現的簡碼的樣子
[grid_shortcode position="first" width="6" vertical="valign-top"]Fügen Sie hier den den gewünschten Inhalt Ihrer neuen Spalte ein.[grid_shortcode]
,所以我期望像
<div class="row"><div class="small-6 columns first">
Fügen Sie hier den den gewünschten Inhalt Ihrer neuen Spalte ein.</div>
或者像
[grid_shortcode position="end" width="6" vertical="valign-top"]Fügen Sie hier den den gewünschten Inhalt Ihrer neuen Spalte ein.[grid_shortcode]
,所以我期望像事端
<div class="small-6 columns end">Fügen Sie hier den den gewünschten Inhalt Ihrer neuen Spalte ein.</div></div>
但它只是殺死我的模板。任何想法或建議?
謝謝你們!
我應該的add_filter( '...', 'do_shortcode')呢? – Xatenev 2014-11-08 16:02:18
widget_text =在小部件中使用時運行短代碼 comment_text =在評論中使用時運行短代碼 the_excerpt =在摘錄中使用時運行短代碼 – ThomasB 2014-11-08 16:23:41