首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我想以10秒的间隔刷新wordpress网站

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

Stack Overflow用户
提问于 2015-03-23 19:25:33
回答 2查看 234关注 0票数 0

我正在写一个插件,想在10秒的间隔刷新小工具。如何做到这一点?

我想间隔调用小部件函数,这样小部件就会刷新。

以下是该插件的代码

代码语言:javascript
复制
<?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' );

 ?>
EN

回答 2

Stack Overflow用户

发布于 2015-03-23 19:32:28

刷新php页面:

代码语言:javascript
复制
<?php
    $url=$_SERVER['REQUEST_URI'];
    header("Refresh: 5; URL=\"" . $url . "\""); // redirect in 5 seconds
    ?>

刷新wordpress link中的插件

票数 0
EN

Stack Overflow用户

发布于 2015-03-23 19:32:44

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

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29209045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档