如何在 wordpress 中获取 get_theme_mod 值到数组中?
how to get get_theme_mod value into array in wordpress?
我想在 wp 主题定制器中通过 theme_mod 值创建一个数组。
例如在这段代码中:
$arr = array(com, net, org);
foreach ($arr as &$value) {
echo "<div id='domain-$value'></div>";
}
我有一个类似上面的数组,其中包含一些顶级域名,我想通过 wp mcomstomizer 动态设置它。
我尝试将 "get_theme_mod( 'tlds' );"(如下所示)放入数组但没有成功,它只将所有值放在一个数组键中。
$arr = array(get_theme_mod( 'tlds' ););
foreach ($arr as &$value) {
echo "<div id='domain-$value'></div>";
}
如何将值放入数组并用逗号分隔每个数组?
get_them_mods()
应该 return 一个可以循环的数组。
https://codex.wordpress.org/Function_Reference/get_theme_mods
您可以使用array_values()
示例:
$arr = get_them_mods();
$temp = array_values($arr);
foreach ($temp as $value) {
echo "<div id='domain-$value'></div>";
}
我通过 explode 找到了解决方案。谢谢
$tlds = get_theme_mod( 'tlds' );
$arr = explode(', ', $tlds);
foreach ($arr as &$value) {
echo "<div id='domain-$value' class='col-md-4 col-xs-6 col-xxs-12 otherdomains'></div>";
}
我想在 wp 主题定制器中通过 theme_mod 值创建一个数组。
例如在这段代码中:
$arr = array(com, net, org);
foreach ($arr as &$value) {
echo "<div id='domain-$value'></div>";
}
我有一个类似上面的数组,其中包含一些顶级域名,我想通过 wp mcomstomizer 动态设置它。
我尝试将 "get_theme_mod( 'tlds' );"(如下所示)放入数组但没有成功,它只将所有值放在一个数组键中。
$arr = array(get_theme_mod( 'tlds' ););
foreach ($arr as &$value) {
echo "<div id='domain-$value'></div>";
}
如何将值放入数组并用逗号分隔每个数组?
get_them_mods()
应该 return 一个可以循环的数组。
https://codex.wordpress.org/Function_Reference/get_theme_mods
您可以使用array_values()
示例:
$arr = get_them_mods();
$temp = array_values($arr);
foreach ($temp as $value) {
echo "<div id='domain-$value'></div>";
}
我通过 explode 找到了解决方案。谢谢
$tlds = get_theme_mod( 'tlds' );
$arr = explode(', ', $tlds);
foreach ($arr as &$value) {
echo "<div id='domain-$value' class='col-md-4 col-xs-6 col-xxs-12 otherdomains'></div>";
}