クラス関数内でhtmlを使用することに何か問題がありますか?DOMで呼び出すので、文字列を返す必要はありません。
public function the_contact_table(){
?>
<div>
some html here
</div>
<?php
}
また、文字列が必要な場合は、このメソッドを使用しますか?より良い方法はありますか、それともこれは比較的標準的ですか?
public function get_single(){
ob_start();?>
<div class='staff-member single'>
<div class='col left'>
<div class='thumbnail'>
thumbnail
</div>
<?php $this->the_contact_table(); ?>
</div>
<div class='col right'>
</div>
</div>
<?php
$content = ob_get_contents();
ob_end_clean();
return $content;
}
アップデート
なぜ私がこれをしているのか説明すべきだった。Wordpressプラグインを作成していて、投稿タイプの出力を制御したいと思います。だから私は以下のようなフィルターを使用しています
public function filter_single($content){
global $post;
if ($post->post_type == 'staff-member') {
$sm = new JM_Staff_Member($post);
$content = $sm->get_single();
}
return $content;
}
ご覧のとおり、WordPressコアに文字列を返す必要があります