0

このクラスを見る

class block {

    function item_html( $post ) {
        ?> <strong><?php the_title(); ?></strong> <?
    }

    function render( $posts ) {
        while ( $posts->have_posts() ) : $posts->the_post();
            $this->item_html($post);
        endwhile; 
        wp_reset_postdata();        
    }
}

これは単なる例です。私のコードでは、 と呼ばれる別の関数を作成する必要がありitem_htmlます。

the_title();と関連する関数を使用したいのですが、引数をitem_html渡すか、そのようにグローバルにする必要があります$postitem_html

    function item_html(){
      global $post;
        ?> <strong><?php the_title(); ?></strong> <?
    } 

グローバルと $post と呼ばれる引数を削除すると、その作業はどうなりますか? 単一の投稿を別の機能に割り当てる最良の方法は何ですか

4

0 に答える 0