前言及思路

生成QQ分享卡片让博客看起来高大上一些,而且显的更官方一点,通过设置想要显示的标题,摘要,图片,meta标签来达到效果,通过判断网址来源来适应不同地方的卡片图片url,各搜索平台收录也会根据这个来进行展示


关于头图大家可以看看我的这篇文章

代码
将代码放到博客的header.php页面,如果是其他博客,请找你的每个页面都会调用的php页面(head标签所在的php页面),然后把下面代码粘贴进去即可,如果不是博客,可以用下面的代码

<!-- QQCard BEGIN -->
     <meta itemprop="name" content="<?php Content::echoTitle($this,$this->options->title,$this->_currentPage); ?>"/>
     <?php if($this->is('index')): ?>
    <meta itemprop="image" content="https://cdn.buleng.xyz/img/2023/3/20_1679290613359.png">
    <meta name="description" itemprop="description" content="<?php $this->options->description(); ?>">
    <?php elseif($this->is('post')): ?>
    <meta itemprop="image" content="<?php $flag=Content::returnHeaderImgSrc($this,'post',0,true);
            if(strpos($flag,'img') !== false){echo 'https://cdn.buleng.xyz/img/2023/3/20_1679290613359.png';}else{echo Content::returnHeaderImgSrc($this,'post',0,true);} ?>">
    <meta name="description" itemprop="description" content="<?php echo Content::excerpt(trim($this->fields->customSummary)!=''?$this->fields->customSummary:$this->excerpt,200); ?>">
    <?php else: ?>
    <meta itemprop="image" content="https://cdn.buleng.xyz/img/2023/3/20_1679290613359.png">
    <meta name="description" itemprop="description" content="<?php $this->options->description(); ?>">
    <?php endif; ?>
    <!-- QQCard END -->

不是博客的代码

<!--360 百度 搜狗 必应 谷歌 -->
<?php if($this->is('post')||$this->is('page')): ?>
<meta property="og:type" content="blog"/>
<meta property="og:image" content="<?php echo Content::returnHeaderImgSrc($this,'post',0,true); ?>"/>
<meta property="og:release_date" content="<?php $this->date('Y-m-j'); ?>"/>
<meta property="og:title" content=" <?php $this->title(); ?>"/>
<meta property="og:description" content=" <?php $this->description() ?>" />
<meta property="og:author" content="<?php $this->author(); ?>"/>
<?php endif; ?>
<!--360 百度 搜狗 必应 谷歌 -->

当然,你也可以都加上,那样会使你的网站看起来有点繁琐

最后修改:2023 年 03 月 24 日 10 : 54 AM
如果觉得此文章有用,请随意打赏