Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在另一个对象内使用WP_Query post对象_Php_Wordpress - Fatal编程技术网

Php 在另一个对象内使用WP_Query post对象

Php 在另一个对象内使用WP_Query post对象,php,wordpress,Php,Wordpress,看到这节课了吗 class block { function item_html( $post ) { ?> <strong><?php the_title(); ?></strong> <? } function render( $posts ) { while ( $posts->have_posts() ) : $posts->the_post();

看到这节课了吗

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();        
    }
}

如果我删除全局和名为$post的arg,它会工作,这是如何发生的?将单个帖子分配给另一个函数的最佳方法是什么

get\u post(id)->post\u title?不确定您一定要写
$post->the_title()
,为什么要写
?>如果不是循环,您必须进行自定义的新wp\u查询或按id获取post
    function item_html(){
      global $post;
        ?> <strong><?php the_title(); ?></strong> <?
    }