正如Gaffen所说:“根据访问的类别更改帖子布局”
首先是主题中的类别模板页面(即category.php)
获取类别id并将其存储在WordPress Transient选项中。
global $wp_query;
//get category id (or name, slug) and store to the transient api
$categoryId = $wp_query->queried_object->cat_ID;
set_transient( \'category_id_visited\', $categoryId, 1 * HOUR_IN_SECONDS );
现在是单身。php或单贴显示模板页面。
从瞬态中获取值,并相应地更改显示
if ( false === ( $category_id_visited = get_transient( \'category_id_visited\' ) ) ) {
// this code runs when there is no valid transient set
//do nothing for now
} else {
echo \'You came by visiting category: \' . $category_id_visited;
//delete transient if required, otherwise it will be expired automatically
delete_transient( \'category_id_visited\' );
}
希望有帮助。