Php 如何在wordpress中从数组中获取值并在前端回显

Php 如何在wordpress中从数组中获取值并在前端回显,php,html,wordpress,Php,Html,Wordpress,如何从位于theme functions.php中的这个数组中获取值(std) $this->settings['google'] = array( 'title' => __( 'Google' ), 'desc' => __( 'This is a description for the text input.' ), 'std' => 'https://www.google.com/+prof

如何从位于theme functions.php中的这个数组中获取值(std)

    $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'
    );
并在我的header.php中回显它 像这样尝试smth,但不起作用

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

  • $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
    文件用户函数中引用您的注释:

    $settings = get_option('mytheme_options');
    echo $settings['google'];
    
    
    
  • **等等**
    @user2092317我收到此错误致命错误:当不在header中的对象上下文中时使用$this.php您的wordpress版本是什么?@ChinnuR 3.7.1您尝试使用默认的wordpress get_settings()函数对吗?这段代码是否在类中?是函数的一部分吗?你提供的信息还不足以帮助你,你可以看看我的函数吗。php不知道是否有类,或者我如何调用该类,我是一个noobCode更新。应该有用。如果没有-显示
    var\u转储(获取选项(“mytheme\u选项”)结果。没有更多的错误,它是echowing,但它是echowing只有1个字母,例如,如果我在Google输入字段的社交设置中输入,它只是echows h,如果我输入123456它echows 1,你可以编辑你的帖子并粘贴到那里你得到的
    var_dump(get_选项('mytheme_选项')?这是我在代码中添加的
    $settings=get_选项(“mytheme_选项”);echo$settings['google']['std']在header.php中?
    
    <?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 ...**