我需要改变
'orderby' => 'date',
with
'orderby' => 'random',
第二次查看主页时 你帮帮我吗?
<?php
$type = 'client';
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 8,
'caller_get_posts'=> 1,
'orderby' => 'date',
'order' => 'DESC'
);
?>
答案 0 :(得分:2)
您可以通过以下方式完成: -
<?php
session_start();
$_SESSION['pageviews'] = (isset($_SESSION['pageviews'])) ? $_SESSION['pageviews'] + 1 : 1;
$type = 'client';
if($_SESSION['pageviews'] == 1){
$order_by_data= 'date';
}else{
$order_by_data= 'random';
}
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 8,
'caller_get_posts'=> 1,
'orderby' => $order_by_data,
'order' => 'DESC'
);
echo $type;echo "<pre/>";print_r($args);echo $_SESSION['pageviews'];
?>
注意: - 基于会话计数器值$args
将改变。谢谢
答案 1 :(得分:2)
<?php
//requires session_start();
$orderBy = "random";
if(!isset($_SESSION['visited'])) {
$_SESSION['visited'] = true;
$orderBy = "date";
}
$type = 'client';
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 8,
'caller_get_posts'=> 1,
'orderby' => $orderBy,
'order' => 'DESC'
);
答案 2 :(得分:0)
您需要使用Cookie或会话来检查用户是否第二次访问了您的网页。
<?php
session_start();
if(!is_set($_SESSION['userVisit'])) {
$type = 'client';
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 8,
'caller_get_posts'=> 1,
'orderby' => 'date',
'order' => 'DESC'
);
$_SESSION['userVisit']=1;
}
else {
$type = 'client';
$args = array(
'post_type' => $type,
'post_status' => 'publish',
'posts_per_page' => 8,
'caller_get_posts'=> 1,
'orderby' => 'random',
'order' => 'DESC'
);
}
我希望我有所帮助