我想以10秒的间隔刷新wordpress网站

时间:2015-03-23 11:25:33

标签: javascript php jquery html wordpress

我正在编写插件,并希望以10秒的间隔刷新小部件。怎么做到这一点?

我想在间隔中调用窗口小部件函数,以便窗口小部件刷新。

以下是插件的代码

<?php
 // Creating the widget 
class rtk_widget extends WP_Widget {

function __construct() {
parent::__construct(
// Base ID of your widget
'rtk_widget', 

// Widget name will appear in UI
__('Realtime Quote', 'rtk_widget_domain'), 

// Widget description
array( 'description' => __( 'Displays Realtime share quote', 'rtk_widget_domain' ), ) 
);
}

// Creating widget front-end
// This is where the action happens
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
// before and after widget arguments are defined by themes
echo $args['before_widget'];
if ( ! empty( $title ) )
echo $args['before_title'] . $title . $args['after_title'];
$stk_options = get_option('stk_settings');


    //echo "ssss";
    if(is_array($stk_options)&&$stk_options['enable']==1)
    {
        $symbols=  explode(" ", $stk_options['stock-names']);
        foreach ($symbols as $symbol) {

        $quote = fetch('GET', $symbol);
        //var_dump($quote[0]);
        echo '<span class="realtime-company">'.$quote[0]->t.' </span>'.'<span class="realtime-quote">'.$quote[0]->l.'</span>';          

        }           
    }   


// This is where you run the code and display the output

echo $args['after_widget'];
}


// Widget Backend 

public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'New title', 'rtk_widget_domain' );
}
// Widget admin form
?>
<p>
</p>
<?php 
}


// Updating widget replacing old instances with new
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
} // Class rtk_widget ends here

// Register and load the widget
function rtk_load_widget() {
    register_widget( 'rtk_widget' );
}
add_action( 'widgets_init', 'rtk_load_widget' );

 ?>

2 个答案:

答案 0 :(得分:0)

刷新php页面:

<?php
    $url=$_SERVER['REQUEST_URI'];
    header("Refresh: 5; URL=\"" . $url . "\""); // redirect in 5 seconds
    ?>

在wordpress link

中刷新插件

答案 1 :(得分:-1)

你无法从php重新加载页面的一部分,你将不得不重新加载整个页面。但我认为这不是你想要的。你应该使用ajax每5秒重新加载一次脚本。