0

我正在尝试在我的 wordpress 选项中回显数组第二级的设置,并且在获取变量时遇到了一些麻烦。此代码确实有效:

 <?php foreach($area['fields'] as $field): ?>
 <?php if ($field['id'] == 'show_border')
  {echo ' show_border';} ?>
 <?php endforeach; ?>

这只是检查是否有一个字段询问您是否要显示边框,是否有任何我想要的回声,无论该字段设置为实际显示边框与否。

我要做的只是回显在“show_border”字段中设置的值。

知道我会怎么做吗?

编辑

array(11) {
  [0]=>
  array(3) {
    ["name"]=>
    string(10) "# of posts"
    ["id"]=>
    string(5) "posts"
    ["type"]=>
    string(4) "text"
  }
  [1]=>
  array(5) {
    ["name"]=>
    string(13) "posts per row"
    ["id"]=>
    string(13) "posts_per_row"
    ["type"]=>
    string(6) "select"
    ["default"]=>
    int(3)
    ["options"]=>
    array(8) {
      [1]=>
      int(1)
      [2]=>
      int(2)
      [3]=>
      int(3)
      [4]=>
      int(4)
      [5]=>
      int(5)
      [6]=>
      int(6)
      [7]=>
      int(7)
      [8]=>
      int(8)
    }
  }
  [2]=>
  array(5) {
    ["name"]=>
    string(11) "header type"
    ["id"]=>
    string(13) "f_header_type"
    ["type"]=>
    string(6) "select"
    ["default"]=>
    string(2) "h4"
    ["options"]=>
    array(6) {
      ["h1"]=>
      string(2) "h1"
      ["h2"]=>
      string(2) "h2"
      ["h3"]=>
      string(2) "h3"
      ["h4"]=>
      string(2) "h4"
      ["h5"]=>
      string(2) "h5"
      ["h6"]=>
      string(2) "h6"
    }
  }
  [3]=>
  array(5) {
    ["name"]=>
    string(5) "icon?"
    ["id"]=>
    string(9) "show_icon"
    ["type"]=>
    string(5) "radio"
    ["default"]=>
    string(3) "yes"
    ["options"]=>
    array(2) {
      ["yes"]=>
      string(3) "yes"
      ["no"]=>
      string(2) "no"
    }
  }
  [4]=>
  array(5) {
    ["name"]=>
    string(13) "icon location"
    ["id"]=>
    string(13) "icon_location"
    ["type"]=>
    string(6) "select"
    ["default"]=>
    string(4) "left"
    ["options"]=>
    array(3) {
      ["left"]=>
      string(4) "left"
      ["right"]=>
      string(5) "right"
      ["top"]=>
      string(3) "top"
    }
  }
  [5]=>
  array(5) {
    ["name"]=>
    string(10) "show text?"
    ["id"]=>
    string(9) "show_text"
    ["type"]=>
    string(5) "radio"
    ["default"]=>
    string(3) "yes"
    ["options"]=>
    array(2) {
      ["yes"]=>
      string(3) "yes"
      ["no"]=>
      string(2) "no"
    }
  }
  [6]=>
  array(5) {
    ["name"]=>
    string(12) "show border?"
    ["id"]=>
    string(11) "show_border"
    ["type"]=>
    string(5) "radio"
    ["default"]=>
    string(2) "no"
    ["options"]=>
    array(3) {
      ["top"]=>
      string(3) "top"
      ["bot"]=>
      string(3) "bot"
      ["no"]=>
      string(2) "no"
    }
  }
  [7]=>
  array(5) {
    ["name"]=>
    string(8) "category"
    ["id"]=>
    string(8) "category"
    ["type"]=>
    string(6) "select"
    ["multiple"]=>
    bool(true)
    ["options"]=>
    array(2) {
      [4]=>
      string(7) "feature"
      [3]=>
      string(6) "slider"
    }
  }
  [8]=>
  array(4) {
    ["name"]=>
    string(14) "custom classes"
    ["id"]=>
    string(14) "custom_classes"
    ["type"]=>
    string(4) "text"
    ["default"]=>
    string(0) ""
  }
  [9]=>
  array(5) {
    ["name"]=>
    string(10) "read more?"
    ["id"]=>
    string(9) "read_more"
    ["type"]=>
    string(5) "radio"
    ["default"]=>
    string(3) "yes"
    ["options"]=>
    array(2) {
      ["yes"]=>
      string(3) "yes"
      ["no"]=>
      string(2) "no"
    }
  }
  [10]=>
  array(4) {
    ["name"]=>
    string(14) "read more text"
    ["id"]=>
    string(14) "read_more_text"
    ["type"]=>
    string(4) "text"
    ["default"]=>
    string(16) "Continue reading"
  }
}

我正在尝试获得类似 ["id"]=> "show_border" 的值并回显它的值。

4

1 回答 1

1

基本上,您无法在 PHP 中获取要从已经加载到服务器端的表单中选择的表单值。

这就像从未来走向过去。

您应该使用 Javascript 代码 + AJAX,而不是 PHP,但它会复杂得多。在不知道网站的完整来源的情况下,不可能用一个简单的答案告诉您。

这也取决于您的开发技能。

于 2012-08-01T09:57:19.530 回答