2016-06-08 32 views
1

添加一個選項頁ACF數據WordPress的簡碼我的代碼:中的functions.php

// Add Shortcode 
function NavotFloatingDiv() { 
    $nHeight = the_field('distance_from_top', 'options'); 
    $nPadding = the_field('div_padding', 'options'); 
    $nBackgroundColor = the_field('div_background_color', 'options'); 
    $nDisplay = the_field('div-display', 'options'); 
    $nDirection = the_field('left-right', 'options'); 
    $nLink = the_field('divlink', 'options'); 
    $nTarget = the_field('divlinktarget', 'options'); 
    $nLinkTitle = the_field('divlinktitle', 'options'); 
    $nContent = the_field('floating_div', 'options'); 
    return '<div id="Navot-Float" class="NavotFlaot" style="z-index: 99999999999; position: fixed; padding:' . $nPadding . 'px; background-color:'. $nBackgroundColor .' ; display: ' . $nDisplay . '; ' . $nDirection . ': 0px ; top: '. $nHeightheight . '%;"><a href=". ' $nLink ' . " target=" ' . $nTarget .' " title=" '. $nLinkTitle .' "><div class="floater-navot-text"> ' . $nContent . '</div></a></div>'; 

} 
add_shortcode('Floating DIV', 'NavotFloatingDiv'); 

的信息存儲,convinently與選項頁面命名選項。目標是在放置簡碼的頁面上爲浮動DIV創建一個迷你插件。花花公子。

我現在無法完全發現問題,我很感激我知道我在使用各種檢索的變量返回HTML標記時做錯了什麼。

+0

更換你的''通過get_field', the_field'因爲第一次顯示,第二個返回 – Pierre

+0

我怕當我添加該代碼的網站仍然崩潰到functions.php ...仍然感謝Explenation! –

+0

我認爲'add_shortcode'的第一個參數不應該包含特殊的字符(如空格) – Pierre

回答

2

這裏是你的更正後的代碼:

add_shortcode('floating_div', 'NavotFloatingDiv'); 
function NavotFloatingDiv(){ 
    $nHeight   = get_field('distance_from_top', 'options'); 
    $nPadding   = get_field('div_padding', 'options'); 
    $nBackgroundColor = get_field('div_background_color', 'options'); 
    $nDisplay   = get_field('div-display', 'options'); 
    $nDirection  = get_field('left-right', 'options'); 
    $nLink   = get_field('divlink', 'options'); 
    $nTarget   = get_field('divlinktarget', 'options'); 
    $nLinkTitle  = get_field('divlinktitle', 'options'); 
    $nContent   = get_field('floating_div', 'options'); 
    return '<div id="Navot-Float" class="NavotFlaot" style="z-index: 99999999999; position: fixed; padding:'. $nPadding . 'px; background-color:'. $nBackgroundColor .' ; display: ' . $nDisplay . '; ' . $nDirection . ': 0px ; top: '. $nHeightheight . '%;"><a href="'. $nLink .'" target=" ' . $nTarget .' " title=" '. $nLinkTitle .' "><div class="floater-navot-text"> ' . $nContent . '</div></a></div>'; 
} 
+0

謝謝〜!有效! –