Z-Blog时间因子,提交格式规范

懋和道人2024年09月03日Z-BlogPHP4481
文章摘要
DaoGPT
此内容根据文章AI生成,并经过人工审核,仅用于文章内容的解释与总结
投诉

时间因子作为百度和头条搜索的重要评估标准,决定了网页内容在搜索引擎中的现。通过分析内容的发布时间、更新时间及用户互动时间,搜索引擎能够判断其价值相关性。定期更新内容,保持页面的新鲜度,并积极引导用户互动,能够提升网站在搜索结果中的排名,吸引更多访客。因此,理解并善用时间因子,对于网站的优化和流量增长至关重要,是达成搜索引擎排名提升的重要途径。很明显,道士我早已经实现了这个功能,不知道大家有没有发现。

image.png

直接附上小道自己的时间因子代码,目前改成了只在文章页面生效。

{php}
// 初始化默认值
$title = '';
$description = '';
$image = '';
$lrDate_time = ''; 

// 仅在文章页面设置 Open Graph 和其他元数据
if ($type == 'article' && isset($article)) {
    // 文章页面
    $title = $article->Title;
    $description = $article->Intro ? $article->Intro : $zbp->description; // 使用文章简介或默认描述
    $image = isset($article->AllImages[0]) ? $article->AllImages[0] : $zbp->host . 'zb_users/upload/2021/07/202107161626384352461436.png'; // 使用文章图像或默认图像
    
    // 直接获取最后评论时间
    $lrDate_time = $article->Time('PostTime', 'Y-m-d\TH:i:s');

    // 将标签转换为直接的JSON数组
    $tags = '[' . implode(',', array_map(function($tag) {
        return '"' . $tag->Name . '"';
    }, $article->Tags)) . ']';

    // 将所有图片URL转换为直接的JSON数组
    $images = '[' . implode(',', array_map(function($img) {
        return '"' . $img . '"';
    }, $article->AllImages)) . ']';
}
{/php}

<!-- Open Graph Protocol for Facebook and general compatibility -->
{if $type == 'article'}
<meta property="og:title" content="{$title}" />
<meta property="og:type" content="article" />
<meta property="og:URL" content="{$article.Url}" />
<meta property="og:image" content="{$image}" />
<meta property="og:description" content="{strip_tags($description)}" />
<meta property="og:site_name" content="{$zbp->name}" />
<meta property="og:updated_time" content="{$article.Time('UpdateTime','Y-m-d\TH:i:s')}" />
<meta property="og:published_time" content="{$article.Time('PostTime','Y-m-d\TH:i:s')}" />
{/if}

<!-- Twitter Card -->
{if $type == 'article'}
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:title" content="{$title}" />
<meta name="twitter:description" content="{strip_tags($description)}" />
<meta name="twitter:image" content="{$image}" />
<meta name="twitter:url" content="{$article.Url}" />
{/if}

<!-- QQ Sharing -->
{if $type == 'article'}
<meta itemprop="name" content="{$title}" />
<meta itemprop="image" content="{$image}" />
<meta name="description" itemprop="description" content="{strip_tags($description)}" />
{/if}

<!-- 头条搜索 -->
{if $type == 'article'}
<meta property="bytedance:published_time" content="{$article.Time('PostTime','Y-m-d\TH:i:s')}" />
<meta property="bytedance:updated_time" content="{$article.Time('UpdateTime','Y-m-d\TH:i:s')}" />
<meta property="bytedance:lrDate_time" content="{$lrDate_time}" />
{/if}

<!-- WeChat Sharing -->
{if $type == 'article'}
<script>
  var WECHAT_TITLE = '{$title}';
  var WECHAT_DESC = '{strip_tags($description)}';
  var WECHAT_IMAGE = '{$image}';
  var WCHAT_NO_GA = '';
</script>
{/if}

<!-- JSON-LD for Structured Data -->
{if $type == 'article'}
<script type="application/ld+json">
{
    "@context": "https://ziyuan.baidu.com/contexts/cambrian.jsonld",
    "@id": "{$article.Url}",
    "appid": "1567508867852255",
    "title": "{$title}",
    "images": {$images},
    "description": "{strip_tags($description)}",
    "pubDate": "{$article.Time('PostTime','Y-m-d\TH:i:s')}",
    "upDate": "{$article.Time('UpdateTime','Y-m-d\TH:i:s')}",
    "lrDate": "{$lrDate_time}",
    "data": {
        "webPage": {
            "headline": "{$title}",
            "tag": {$tags},
            "pcUrl": "{$article.Url}",
            "wapUrl": "{$article.Url}",
            "appUrl": "{$article.Url}",
            "mipUrl": "{$article.Url}",
            "fromSrc": "{$zbp->name}",
            "datePublished": "{$article.Time('PostTime','Y-m-d\TH:i:s')}"
        }
    }
}
</script>
{/if}

粘贴在Z-Blog的主题head头部模板就可以了,如果觉得有用,请尽情施舍道士,道士会很喜欢的。

扫描二维码推送至手机访问。

版权声明:本文由 南蛮子懋和 发布,如需转载请遵循《声明》注明出处。

本文链接:https://www.dao.js.cn/new/2024090311412.shtml

返回列表

没有更早的文章了...

下一篇:让Z-Blog评论必须填邮箱、网址等信息

“Z-Blog时间因子,提交格式规范” 的相关文章

让Z-Blog评论必须填邮箱、网址等信息

让Z-Blog评论必须填邮箱、网址等信息

鸣谢@隔壁老李、@拓源网、@沉冰浮水、@豫唐网络四位大佬的思路及技术支撑,使得小道又学会了一个巧妙地姿势。缘起啊,说来话长。有位道友找小道换友链,结果在写评论的时候,居然邮箱、主页什么的全都没填,小道...

巧用Cloudflare功能实现Z-BlogPHP智能AI摘要

巧用Cloudflare功能实现Z-BlogPHP智能AI摘要

特别鸣谢@Mayx的鼎力支持,使小道实现了巧用Cloudflare功能实现Z-BlogPHP智能AI摘要的基本功能。思路https://mayx.eu.org/2024/07/03/ai-summar...

Z-BlogPHP调用文章总数、评论总数等常用标签

Z-BlogPHP调用文章总数、评论总数等常用标签

文章总数:{$zbp->cache->all_article_nums} 页面总数:{$zbp->cache->all_page_nums} 标签总数:{$...

升级拓源纯净主题tpure的注意事项

升级拓源纯净主题tpure的注意事项

由于站点已经是PHP高版本,每次升级主题的时候,需要重新下载纯净主题PHP7.4~PHP8邮件通知组件,不然的话整个网站评论会提示没有each函数。一定要长记性,长记性。目前主题的离线IP数据是没有I...

评论列表

逍遥自在
逍遥自在    Lv.3筑基培元 来自AI星球  Google Chrome 100.0.4896  Android 11 (Red Velvet Cake)
2024年09月03日

代码提供了获取和生成关于文章的信息的时间、标签及URL等信息,复制并粘贴在Z-Blog主题的head模板中,以帮助SEO优化和提高网站性能!感谢分享者~

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。

请如实填写常用的真实邮箱,方便后续的回复邮件通知。