自动刷新wordpress主页

时间:2013-04-04 19:27:07

标签: wordpress refresh

如何每3分钟自动刷新一次主页?

我只想要index.php而不是所有页面(不会将代码放在header.php中)。

我应该使用的代码是什么以及放置在哪里?这是我的index.php第一行:

<?php
/**
 * @package WordPress
 * @subpackage Default_Theme
 */

get_header(); 
?>
<!--Body Container Start Here -->

非常感谢!!

3 个答案:

答案 0 :(得分:4)

不确定你的主题是什么,但是你可以使用钩子,比如wp_head并检查你想要的条件。这可以插入functions.php或其他地方。

<?php
/**
 * @package WordPress
 * @subpackage Default_Theme
 */

function check_if_this_is_home_and_then() {
    if( is_home() ) {

?>

<meta http-equiv="refresh" content="180;url=http://stackoverflow.com/">

<?php

    }
}

add_action( 'wp_head', 'check_if_this_is_home_and_then' );

get_header(); 
?>

<!--Body Container Start Here -->

答案 1 :(得分:2)

为什么不在主页上使用元刷新标记?

<meta http-equiv="refresh" content="180;url=http://stackoverflow.com/">

答案 2 :(得分:0)

您可以添加以下内容;

<script language="JavaScript">
     var sURL = unescape(window.location.pathname);
     var intValue = 0;
     function doLoad()
     {
         intValue=setTimeout( "refresh()", 300*1000 );
     }

    function refresh()
     {
         window.location.href = sURL;
     }

    function noRefresh(e)
     {
         switch (e.keyCode) {
             case 40:
             case 39:
             case 38:
             case 37:
             case 34:
             case 33:
                 break;
             default:
                 clearTimeout(intValue);
         }

    }

    if ($.browser.mozilla) {
         $(document).keypress(noRefresh);
     } else {
         $(document).keydown(noRefresh);
     }

    $(document).ready(doLoad());
 </script>
 <noscript>
     <meta http-equiv="refresh" content="300">
 </noscript>

如上所述,将<meta http-equiv="refresh" content="300">内的300修改为60,将每60秒更新一次。

希望有效!

**编辑:这将在你的'header.php'中修改:)

相关问题