分享:SEO加強(qiáng)效果!多個(gè)隨機(jī)內(nèi)容(隨機(jī)刷新不變+修改時(shí)間改變)+ 后臺自主控制
首先站在SEO的角度看:做這個(gè)功能對于谷歌或百度都是有幫助。可以解決產(chǎn)品頁面的內(nèi)容相似度問題。
其次也能補(bǔ)充產(chǎn)品頁面的內(nèi)容豐富度。
如果你是高手就不不必看了。這里也要感謝群里的QQ:501574022 (阿輝) 無償?shù)臒嵝募夹g(shù)支持!
開始我的小白級教程:
在頻道模型 >>>創(chuàng)建: 字段 --單選--->>>>


\extend\function.php >>>
注意:需要在 extend\ 目錄下建一個(gè) json 文件夾
——————————————————————————————————————————————
代碼如下:
if (!function_exists('diy_rand_snjbs')) {
function getRandomElementsFromArray($inputArray, $numElements) {
if ($numElements <= 0) {
return []; // 如果要選擇的元素?cái)?shù)量小于等于0,返回一個(gè)空數(shù)組
}
$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'];
// 構(gòu)建結(jié)果存儲文件名
$uniqueIdentifier = $add_time . '_' . $aid; // 按照您的需求構(gòu)建唯一標(biāo)識符
$resultFile = 'extend/json/diy_rand_snjbs_' . $uniqueIdentifier . '.json';
// 讀取保存的結(jié)果數(shù)組
if (file_exists($resultFile)) {
$resultJson = file_get_contents($resultFile);
$result = json_decode($resultJson, true);
} else {
$result = [];
}
// 檢查結(jié)果中是否已存在指定日期和ID的內(nèi)容
foreach ($result as $item) {
if ($item['date'] == $add_time && $item['aid'] == $aid) {
echo $item['content'];
return;
}
}
// 默認(rèn)內(nèi)容數(shù)組
$contentArray = array(
'Tightening lug nuts on a car wheel',
'Assembling bicycle components',
'Robotics and automation',
'Research and development in various industries'
);
// 從數(shù)組中隨機(jī)選擇指定數(shù)量的元素
$selected_content = getRandomElementsFromArray($contentArray, $numElements);
// 將選定的內(nèi)容用段落標(biāo)簽包裝起來
$lastContent = implode('', array_map(function ($content) {
return '<p>' . $content . '</p>';
}, $selected_content));
$result[] = [
'date' => $add_time,
'aid' => $aid,
'content' => $lastContent
];
// 將結(jié)果數(shù)組保存到文件中
file_put_contents($resultFile, json_encode($result));
// 輸出內(nèi)容
echo $lastContent;
}
}
function diy_rand_snjbs2($field, $numElements = 7) {
$add_time = $field['add_time'];
$aid = $field['aid'];
// 構(gòu)建結(jié)果存儲文件名
$uniqueIdentifier = $add_time . '_' . $aid; // 按照您的需求構(gòu)建唯一標(biāo)識符
$resultFile = 'extend/json/diy_rand_snjbs2_' . $uniqueIdentifier . '.json';
// 讀取保存的結(jié)果數(shù)組
if (file_exists($resultFile)) {
$resultJson = file_get_contents($resultFile);
$result = json_decode($resultJson, true);
} else {
$result = [];
}
// 檢查結(jié)果中是否已存在指定日期和ID的內(nèi)容
foreach ($result as $item) {
if ($item['date'] == $add_time && $item['aid'] == $aid) {
echo $item['content'];
return;
}
}
// 默認(rèn)內(nèi)容數(shù)組
$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'
);
// 從數(shù)組中隨機(jī)選擇指定數(shù)量的元素
$selected_content = getRandomElementsFromArray($contentArray, $numElements);
// 將選定的內(nèi)容用段落標(biāo)簽包裝起來
$lastContent = implode('', array_map(function ($content) {
return '<p>' . $content . '</p>';
}, $selected_content));
$result[] = [
'date' => $add_time,
'aid' => $aid,
'content' => $lastContent
];
// 將結(jié)果數(shù)組保存到文件中
file_put_contents($resultFile, json_encode($result));
// 輸出內(nèi)容
echo $lastContent;
}
———————————————————————————————————————————————
4. 前端 模板文件 調(diào)用:

——————————————————————————————
{eyou:switch name='$eyou.field.yy2v1'}
{eyou:case value='HTW'}應(yīng)用1:{$eyou.field|diy_rand_snjbs}{/eyou:case}
{eyou:case value='HT'}應(yīng)用2:{$eyou.field|diy_rand_snjbs2}{/eyou:case}
{eyou:case value='HWP'}應(yīng)用3{/eyou:case}
{eyou:case value='CTW'}應(yīng)用4{/eyou:case}
{eyou:case value='PTW'}應(yīng)用5{/eyou:case}
{eyou:case value='MTW'}應(yīng)用6{/eyou:case}
{eyou:default /}默認(rèn)
{/eyou:switch}
————————————————————————
5.后臺
選一個(gè) 自己對應(yīng) 欄目下 對應(yīng)產(chǎn)品的應(yīng)用領(lǐng)域。
------------------------------------
結(jié)束!!