Cookie,甚至HTML5local storage, 似乎是实现这一点的好方法。以下是一些可以作为起点的基本代码。帖子ID在cookie中存储为CSV。
// Load current favourite posts from cookie
$favposts = (isset($_COOKIE[\'favposts\'])) ? explode(\',\', (string) $_COOKIE[\'favposts\']) : array();
$favposts = array_map(\'absint\', $favposts); // Clean cookie input, it\'s user input!
// Add (or remove) favourite post IDs
$favposts[] = $post->ID;
// Update cookie with new favourite posts
$time_to_live = 3600 * 24 * 30; // 30 days
setcookie(\'favposts\', implode(\',\', array_unique($favposts)), time() + $time_to_live);