2010-03-11 44 views
1

基本上像克雷格列表將用戶重定向到一個特定的類別。一旦你在craigslist上選擇了城市,下次你去網站時,它會將你重定向到你選擇的城市。WP:使用cookie

我想達到什麼:當一個人來到現場,並選擇特定的類別,下一次他們來到現場(返回用戶) - 該頁面將打開在該類別的部分。

我認爲這將是很容易通過設置cookie辦時,訪問者點擊類別鏈接(或當類別頁面加載)上。當他們返回以下時間時,會讀取Cookie,然後相應地重定向頁面。

不幸的是我的PHP和餅乾的知識是有限的,(因此我尋找答案),所以我要問,如果有人能幫助我出去!

任何人有任何想法?

謝謝!

+0

可能重複的[wordpress,類別重定向使用cookie](http://stackoverflow.com/questions/2395175/wordpress-category-redirect-using-cookies) – Kevin 2014-04-15 15:19:45

回答

2

markratledge具有良好的鏈接,但WordPress的有一個內置的功能,將用戶重定向並通過HTTP狀態碼,以及它的設置餅乾自己的首選方法。

給這個一杆。我也不太清楚,如果它的作品,因爲我無法測試出來的權利,但它應該指向你在正確的方向。

function user_cat() 
{ 
    //Check to see if our cookie is set 
    if(isset($_COOKIE['visitorhome'])) 
    { 
     //Redirect to the link defined in the cookie 
     wp_redirect($_COOKIE['visitorhome'], 302); 
    } 
    else 
    { 
     //If it's a category page than get the current URL set the cookie with it. 
     if(is_category()) 
     { 
      $user_cat = get_permalink(); 
      setcookie("visitorhome", $user_cat, time()+86400, "/", str_replace('http://www','',get_bloginfo('url'))); 
     } 
    } 
} 
add_action('init', 'user_cat');