나는 지난 며칠 동안 Wordpress 테마 프로젝트를 작업 해왔고 OOP (나는 주로 PHP 스크립터가 아니라 테마 개발자)를 사용하여 동적 옵션 페이지를 올바르게 실행하는 방법에 주저하고 있습니다. 함수가 foreach 루프에서 필요한만큼 여러 번 호출 될 것입니다 때문에이 코드 예제에서 foreach 내에서 함수 호출?
<?php
$footerpage = new optionpage;
$footerpage->title = 'Footer';
$footerpage->titleprint = ' Footer Options';
$footerpage->slug = 'footer';
$footerpage->html = array(
'1' => array(
'type' => 'textarea',
'class' => 'large-text',
'name' => 'html',
'title' => 'HTML',
'description' => 'Type in whatever HTML you\'d like to see in the footer here:',
),
'2' => array(
'type' => 'input',
'class' => 'large-text',
'name' => 'background-color',
'title' => 'Background Color',
'description' => ' Choose a Background Color:'
),
);
class optionpage {
public $title;
public $titleprint;
public $slug;
public $html = array();
......
......
......
public function ab_settings() {
register_setting($this->slug, 'ab_options');
add_settings_section('ab_section', '', array(&$this, 'ab_do_titleprint'), 'ab_' . $this->slug . '_options', 'ab_options');
foreach ($this->html as $key => $html) {
add_settings_field($key, $html['title'], array(&$this, 'ab_do_htmlprint'), 'ab_' . $this->slug . '_options', 'ab_section');
}
}
public function ab_do_htmlprint() {
$html = $this->html[$key];
?>
<p><?php echo $html['description'] ?></p>
<<?php echo $html['type'] ?>
id="<?php echo $html['id'] ?>"
class="<?php echo $html['class'] ?>"
name="<?php echo $html['name'] ?>">
<?php get_option ($html['name'])?>
</<?php echo $html['type'] ?>>
<?php
}
......
......
?>
, 나는,가 호출되어있어 foreach는 식을 인식하는 기능 ab_do_htmlprint를 얻기 위해 노력하고있어.
변수 이름에 함수를 추가하는 것과 같은 여러 가지 작업을 시도했지만 동일한 코드의 여러 함수가 필요합니다. 다른 이름을 사용해야합니다. 나는 또한 다양한 변수를 참조로 전달하려고했지만, 그 중 하나도 작동하지 않았고 필요하다면 올바르게 수행하지 못했을 수도 있습니다.
어쨌든이 작업을 효율적으로 수행 하시겠습니까?
나는 따라갈 수 없다. ab_do_htmlprint의 동작은 호출 된 위치에 따라 어떻게 달라야합니까? 나의 직감은 간단한 논증이지만 구체적인 내용을 이해하지 못한다. –
내가 원하는 것은 ab_do_htmlprint 함수가 다차원 배열 안에있는 각 옵션의 HTML을 출력하도록하는 것이다.foreach 루프 내에서 ab_do_htmlprint가 호출 될 때마다 각 옵션이 내가 작성한 옵션 페이지에 표시됩니다. 말이 돼? – James