2015-04-27 41 views
0

我有一個函數創建了一個名爲「content-wrapper」的div。在特殊的場合,我需要這個div內的其他類和我使用此功能試了一下:創世紀 - 如何將其他課程傳遞給genesis_markup?

function content_wrapper($function, $title = '', $first = false) { 
    if ('open' != $function && 'close' != $function) 
     return; 

if ('open' == $function) { 
    if ($first == true) { 
     genesis_markup(array(
      'html5' => '<div %s>', 
      'xhtml' => '<div class="content-wrapper content-wrapper-first">', 
      'context' => 'content-wrapper content-wrapper-first', 
     )); 

但輸出

<div class="content-wrappercontent-wrapper-first"> 

有誰知道爲什麼空白被刪除,我怎麼可以添加它?我甚至在功能擴展到

function content_wrapper($function, $title = '', $args = '') { 

的$ args將是一個數組,其中我可以通過其他的類,但這不能正常工作。即使genesis_attr-content-wrapper也無法正常工作,因爲它將附加類添加到頁面上的每個內容包裝器。

有人有想法嗎?

謝謝。

回答

2

當它運行sanitize_html_class($ context)時,它看起來在創建主題的markup.php文件中的函數genesis_parse_attr()中刪除了空格。你有使用genesis_attr-context-wrapper過濾器的正確思想,但是這個上下文在其他地方使用,所以它會被調用很多次。爲了您的情況,只需要在需要時添加該類,請將上下文更改爲僅「content-wrapper-first」,並創建一個名爲genesis_attr-context-wrapper-first的過濾器。鉤住這個過濾器並添加上下文包裝類(以及任何其他你想要的)。

於是呼genesis_markup這樣的:

genesis_markup(array(
    'html5' => '<div %s>', 
    'xhtml' => '<div class="content-wrapper content-wrapper-first">', 
    'context' => 'content-wrapper-first', 
)); 

然後勾由於上下文是纔會被調用時genesis_markup有語境「內容包裝爲先」的

add_filter('genesis_attr_content-wrapper-first','myFilterFunction'); 

function myFilterFunction($attributes) { 
    $attributes['class'] = $attributes['class'] . ' ' . 'content-wrapper'; 
    return $attributes; 
} 

過濾器content-wrapper-first,它將已經在$attributes['class']變量中。

相關問題