1. 当前位置: 网站首页 >  零散代码 >  EMLOG文章内容页展开全部

EMLOG文章内容页展开全部

为emlog文章内容页添加功能:
EMLOG文章内容页展开全部

1.实现用户访问时只显示部分内容,需要点击展开全部才显示全部内容。
2.蜘蛛爬虫访问时直接爬取全部内容。
打开模版文件echo_log.php,找到<?php echo $log_content;?>替换成下面代码

<?php
$content = $log_content; // 获取文章内容
$showContentLength = 500; // 设置展示内容的长度,根据需要进行调整
$userAgent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
$isSpider = false; // 判断是否为蜘蛛爬虫
$spiderKeywords = array('spider', 'bot', 'crawl', 'slurp', 'spider'); // 常见蜘蛛爬虫关键词
foreach ($spiderKeywords as $keyword) {
if (stripos($userAgent, $keyword) !== false) {
$isSpider = true;
break;
}
}
if ($isSpider) {
echo $content;
} else {
if (mb_strlen($content) > $showContentLength) {
$showContent = mb_substr($content, 0, $showContentLength) . '...';
$fullContent = $content;
echo '<div id="content">' . $showContent . '</div>';
echo '<a class="expand-link" href="javascript:;" onclick="expandContent()"><div class="all-content-box"><div class="all-content bk">展开全文</div></div></a>';
} else {
echo '<div id="content">' . $content . '</div>';
}
}
?> 


展开全文


版权说明 手机扫码阅读
版权所有:《路由通》 => 《EMLOG文章内容页展开全部
本文地址:https://nctoro.com/daima/555.html
除非注明,文章均为 《路由通》 原创,欢迎转载!转载请注明本文地址,谢谢。

发表评论

联系我们

在线咨询:点击这里给我发消息

微信号:master_135

工作日:9:00-23:00,节假日休息

扫码关注