分享:SEO加强效果!多个随机内容(随机刷新不变+修改时间改变)+ 后台自主控制
首先站在SEO的角度看:做这个功能对于谷歌或百度都是有帮助。可以解决产品页面的内容相似度问题。
其次也能补充产品页面的内容丰富度。
如果你是高手就不不必看了。这里也要感谢群里的QQ:501574022 (阿辉) 无偿的热心技术支持!
开始我的小白级教程:
在频道模型 >>>创建: 字段 --单选--->>>>


\extend\function.php >>>
注意:需要在 extend\ 目录下建一个 json 文件夹
——————————————————————————————————————————————
代码如下:
if (!function_exists('diy_rand_snjbs')) {
function getRandomElementsFromArray($inputArray, $numElements) {
if ($numElements <= 0) {
return []; // 如果要选择的元素数量小于等于0,返回一个空数组
}
$randomKeys = array_rand($inputArray, $numElements);
$randomElements = [];
if (is_array($randomKeys)) {
foreach ($randomKeys as $key) {
$randomElements[] = $inputArray[$key];
}
} else {
$randomElements[] = $inputArray[$randomKeys];
}
return $randomElements;
}
function diy_rand_snjbs($field, $numElements = 7) {
$add_time = $field['add_time'];
$aid = $field['aid'];
// 构建结果存储文件名
$uniqueIdentifier = $add_time . '_' . $aid; // 按照您的需求构建唯一标识符
$resultFile = 'extend/json/diy_rand_snjbs_' . $uniqueIdentifier . '.json';
// 读取保存的结果数组
if (file_exists($resultFile)) {
$resultJson = file_get_contents($resultFile);
$result = json_decode($resultJson, true);
} else {
$result = [];
}
// 检查结果中是否已存在指定日期和ID的内容
foreach ($result as $item) {
if ($item['date'] == $add_time && $item['aid'] == $aid) {
echo $item['content'];
return;
}
}
// 默认内容数组
$contentArray = array(
'Tightening lug nuts on a car wheel',
'Assembling bicycle components',
'Robotics and automation',
'Research and development in various industries'
);
// 从数组中随机选择指定数量的元素
$selected_content = getRandomElementsFromArray($contentArray, $numElements);
// 将选定的内容用段落标签包装起来
$lastContent = implode('', array_map(function ($content) {
return '<p>' . $content . '</p>';
}, $selected_content));
$result[] = [
'date' => $add_time,
'aid' => $aid,
'content' => $lastContent
];
// 将结果数组保存到文件中
file_put_contents($resultFile, json_encode($result));
// 输出内容
echo $lastContent;
}
}
function diy_rand_snjbs2($field, $numElements = 7) {
$add_time = $field['add_time'];
$aid = $field['aid'];
// 构建结果存储文件名
$uniqueIdentifier = $add_time . '_' . $aid; // 按照您的需求构建唯一标识符
$resultFile = 'extend/json/diy_rand_snjbs2_' . $uniqueIdentifier . '.json';
// 读取保存的结果数组
if (file_exists($resultFile)) {
$resultJson = file_get_contents($resultFile);
$result = json_decode($resultJson, true);
} else {
$result = [];
}
// 检查结果中是否已存在指定日期和ID的内容
foreach ($result as $item) {
if ($item['date'] == $add_time && $item['aid'] == $aid) {
echo $item['content'];
return;
}
}
// 默认内容数组
$contentArray = array(
'Tightening lug nuts on a car wheel',
'Assembling bicycle components',
'Securing fasteners in woodworking',
'Installing plumbing fixtures',
'Mounting electrical panels',
'Repairing small engines',
'Maintaining firearms',
'Research and development in various industries'
);
// 从数组中随机选择指定数量的元素
$selected_content = getRandomElementsFromArray($contentArray, $numElements);
// 将选定的内容用段落标签包装起来
$lastContent = implode('', array_map(function ($content) {
return '<p>' . $content . '</p>';
}, $selected_content));
$result[] = [
'date' => $add_time,
'aid' => $aid,
'content' => $lastContent
];
// 将结果数组保存到文件中
file_put_contents($resultFile, json_encode($result));
// 输出内容
echo $lastContent;
}
———————————————————————————————————————————————
4. 前端 模板文件 调用:

——————————————————————————————
{eyou:switch name='$eyou.field.yy2v1'}
{eyou:case value='HTW'}应用1:{$eyou.field|diy_rand_snjbs}{/eyou:case}
{eyou:case value='HT'}应用2:{$eyou.field|diy_rand_snjbs2}{/eyou:case}
{eyou:case value='HWP'}应用3{/eyou:case}
{eyou:case value='CTW'}应用4{/eyou:case}
{eyou:case value='PTW'}应用5{/eyou:case}
{eyou:case value='MTW'}应用6{/eyou:case}
{eyou:default /}默认
{/eyou:switch}
————————————————————————
5.后台
选一个 自己对应 栏目下 对应产品的应用领域。
------------------------------------
结束!!