目前,我正在Java背景下学习PHP和Wordpress开发。如何访问中的变量public function Example_Widget()
从…起public function widget( $args, $instance )
? 当我使用var_dump($Example_Widget->$ranNum);
它显示为null。这当然不是真的。这对我来说是全新的。
<?php
add_action( \'widgets_init\', \'example_load_widgets\' );
function example_load_widgets() {
register_widget( \'Example_Widget\' );
}
class Example_Widget extends WP_Widget {
function __construct() {
parent::__construct(
\'Random_Profile_Widget\', // Base ID
\'Random Profiles\', // Name
array( \'description\' => __( \'Drag this widget to any sidebar to display random profiles.\', \'text_domain\' ), ) // Args
);
}
public function Example_Widget() {
$args = array(
\'posts_per_page\' => 99,
\'offset\' => 0,
\'category\' => \'\',
\'category_name\' => \'\',
\'orderby\' => \'post_date\',
\'order\' => \'DESC\',
\'include\' => \'\',
\'exclude\' => \'\',
\'meta_key\' => \'\',
\'meta_value\' => \'\',
\'post_type\' => \'resume\',
\'post_mime_type\' => \'\',
\'post_parent\' => \'\',
\'post_status\' => \'publish\',
\'suppress_filters\' => true
);
$resumes = get_posts($args);
$ranNum = rand ( 0 , sizeof($resumes) - 1 );
$resume = $resumes[$ranNum];
}
public function widget( $args, $instance ) { ?>
<p><?php var_dump($Example_Widget->$ranNum); ?></p>
<?php }
}
/* Stop Adding Functions Below this Line */
?>