2012-07-25 140 views
1

我爲我的表弟創建了一個汽車預訂網站,並且我已經使用wordpress創建了它,他不希望預訂頁面僅在上午10點到下午5點之間提供。否則,該頁面必須顯示預訂小時結束。請給我這個想法。如何在上午10點到下午5點之間顯示wordpress頁面?

+4

多可怕的想法。能夠24/7全天候工作是在線體驗的主要優勢之一。 – Quentin 2012-07-25 13:32:26

回答

1

我已經結束了這個頁面,只是把這個代碼片斷裏你functions.php

add_filter('the_content', 'check_time'); 
function check_time($content) 
{ 
    $pagename = get_query_var('pagename'); 
    if($pagename=='booking_page') // page name assumed 'booking_page' here 
    { 
     date_default_timezone_set('Asia/Dhaka'); // set your timezone if it was not set, currently it's mine 
     $currentTime=strtotime(date("H:i", time())); 
     $start=strtotime("10:00"); // 10am 
     $end=strtotime("17:00"); // 5pm 

     if($currentTime >= $start && $currentTime <= $end) 
     { 
      return $content; // return the original content, it's intime 
     } 
     else 
     { 
      $content="Booking hour ends!"; // change the content to "Booking hour ends!" 
     } 

    } 
    return $content; 
} 

我測試過它並完美地工作,但不知道這是否是完美的方式。

+1

謝謝,它完美的作品:) – 2012-07-25 17:37:25

+0

不客氣:-) – 2012-07-25 17:38:05

+1

是啊,謝謝..! – 2012-07-26 04:33:35

1

您可以使用index.php自身的當前時間進行檢查。如果當前時間是不是你指定的時間之間重定向到顯示了一些消息

相關問題