繁体   English   中英

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

[英]How to get value from an array and echo it in frontend in wordpress

如何从我的主题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文件中引用您的注释用户get_option函数:

$settings = get_option('mytheme_options');
echo $settings['google'];
<?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 ...**

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM