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> <?
}