Wordpress 获取小部件方法中的当前帖子信息
假设小部件位于post循环中,如何从Wordpress 获取小部件方法中的当前帖子信息,wordpress,widget,Wordpress,Widget,假设小部件位于post循环中,如何从小部件方法(下面的代码)内部获取当前帖子的信息,例如get_category()、get_post_title()等 class My_Widget extends WP_Widget { public function widget( $args, $instance ) { // outputs the content of the widget } } 您可以通过以下方式获取帖子id: $post\u id=$GLO
小部件方法(下面的代码)内部获取当前帖子的信息,例如get_category()、get_post_title()等
class My_Widget extends WP_Widget {
public function widget( $args, $instance ) {
// outputs the content of the widget
}
}
您可以通过以下方式获取帖子id:
$post\u id=$GLOBALS['post']->id代码>
使用$post\u id,您可以获得所需的任何信息。你好,Phillip。成功了!在WordPress上编写这样的代码是一种好的做法吗?在functions.php上的类方法中是否有其他方法获取这些信息?