2013-11-03 52 views
1

呼應它在前端我怎樣才能從這種陣列位於我的主題的functions.php如何從一個數組中獲得價值,並在WordPress

$this->settings['google'] = array(
     'title' => __('Google'), 
     'desc' => __('This is a description for the text input.'), 
     'std'  => 'https://www.google.com/+profile_name', 
     'type' => 'text', 
     'section' => 'social' 
    ); 

,並呼應它的值(STD)我header.php 試過這樣的行爲並沒有奏效。

<li><a href="#" class="social-google"> 
<?php $google = get_settings['google']['std']; echo $google;?></a></li> 
+0

@ user2092317我得到這個錯誤 致命錯誤:使用$這個時候不是在對象上下文中的header.php – Adrian

+0

什麼是你的WordPress的版本? –

+0

@ChinnuR 3.7.1 latest – Adrian

回答

1
<?php 
$settings = get_option('mytheme_options'); 
?>  

<li><a href="<?php echo $settings['google']; ?>" class="social-google"></a></li> 
<li><a href="<?php echo $settings['twitter']; ?>" class="social-twitter"></a></li> 

**and so on ...** 
2

$this->settings調用對象變量。你是否定義了functions.php中的任何課程?如果是,請先撥打header.php。如果沒有,那麼沒有$this來電。

做這樣的事情:

//functions.php 
$settings['google'] = array(...); 
global $settings; 

//header.php 
global $settings; 
echo $settings['google']['std']; 

如果在功能包你$settings['google'] = array(...);然後記得的功能開始叫global


參考您的評論在您的header.php文件中的用戶get_option功能:

$settings = get_option('mytheme_options'); 
echo $settings['google']; 
+0

你可以看看我的functions.php http://www.seoadsem.com/test1/functions.txt不知道是否有任何課程,或者我該如何叫課堂,我是一種noob – Adrian

+0

代碼已更新。應該管用。如果沒有 - 告訴我'var_dump(get_option('mytheme_options'));'結果。 – speccode

+0

沒有更多的錯誤,它是echowing,但它只echowing只有一個字母,例如,如果我在谷歌輸入字段http://www.google.com社交設置中輸入,它只能回h,如果我輸入123456 it echows 1 – Adrian