脚本宝典收集整理的这篇文章主要介绍了php – wordpress显示之前未显示的随机帖子,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
query_posts(array('orderby' => 'rand','post__not_in' => $_SESSION['watched'],'showposts' => 1));
并且会话的代码不再高级
if(!in_array($post->ID,$_SESSION['watched'])){ array_push($_SESSION['watched'],$post->ID); }
试试这个:
function removeSeenPosts ($where) { global $wpdb; if (count($_SESSION['watched']) > 0) { $where .= ' AND ' . $wpdb->posts . '.ID NOT IN(' . implode (',',$_SESSION['watched']) . ') '; } return $where; } add_filter('posts_where','removeSeenPosts'); query_posts(array('orderby' => 'rand','showposts' => 1)); remove_filter('posts_where','removeSeenPosts');
如果这没有帮助(我实际上怀疑),问题显然与会话中的帖子ID存储有关.
我想到两件事:
>除了标题已被发送之外,是否可以填充$_SESSION?我不记得了……
>将帖子存储在适当的cookie中似乎是一种可行的替代方案,并且作为额外的奖励,会使存储在会话中保持不变.
未经测试的插件实现:
function setViewedPostCookies() { if (is_single()) { global $wp_query; if (!isset($_COOKIE['watched'])) { $excluded_posts = array(); } else { $excluded_posts = implode(',$_COOKIE['watched']); } $excluded_posts[] = $wp_query->post->ID; $excluded_posts = array_unique($excluded_posts); setcookie('watched',explode(',$excluded_posts),time() + 3600000,'/'); } } add_action( 'get_header','setViewedPostCookies' );
以上是脚本宝典为你收集整理的php – wordpress显示之前未显示的随机帖子全部内容,希望文章能够帮你解决php – wordpress显示之前未显示的随机帖子所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。