当前位置 : 主页 > AI搜索优化 > 正文

AI搜索优化结构化数据Schema设置,适配DedeCMS、WordPress

原创

重庆seo 2026-10-20 阅读()

AI 优化改造全网没有完整教程,其实也不复杂,可以把网站页面大致分为:首页、产品类、案例类、FAQ、新闻资讯(文章)类。网站可以再区分:机械设备、博客、普通企业官网。

最让人头疼的估计是AI 搜索的 GEO 结构化数据 Schema 设置,不论哪个 CMS 都没有现成的插件工具可以省事。这里以 DedeCMS 和 WordPress 为例,两者都是使用人最多的CMS,前者国内PHP类的CMS方法相似,后者用得最为广泛。通用以常见的机械设备、博客为例,分享各个页面的 Schema 设置方法。

DedeCMS 博客类 Schema 设置

博客网站主要有首页、分类页、关于我们页,大多数是调用织梦标签,//标注的部分自行修改。以下 Schema 代码加到指定页面模板的 </head> 之前。

<!-- 首页结构化数据标记 -->
<script type="application/ld+json">
 {
   "@context": "https://schema.org",
   "@graph": [
     {
       "@type": "WebSite",
       "url": "{dede:global.cfg_basehost/}",  //首页链接,后面没有“/”
       "name": "{dede:global.index_title/}",  //增加的自定义字段,若无会报错(首页seo标题,不是网站名称)
       "description": "{dede:global.cfg_description/}"  //首页描述
     },
    {
       "@type": "Person",
       "name": "吖七(许祝岗)",  //作者名称,自行修改
       "alternateName": "吖七(许祝岗)", 
       "jobTitle": "资深白帽SEO顾问",  //职称,自行修改
       "description": "10年SEO实战经验……"  //网站描述,自行修改
     }
   ]
 }
</script>

<!--文章结构化数据标记-->
<script type="application/ld+json">
 {
  "@context": "https://schema.org",
  "@graph": [
   {
    "@type": "BreadcrumbList", //面包屑
    "itemListElement": [
     {
      "@type": "ListItem",
      "position": 1,
      "name": "主页",
      "item": "{dede:global.cfg_basehost/}/" //后面有“/”
     },
     {
      "@type": "ListItem",
      "position": 2,
      "name": "{dede:field.typename/}",
      "item": "{dede:type}[field:typeurl/]{/dede:type}"
     },
     {
      "@type": "ListItem",
      "position": 3,
      "name": "{dede:field.title/}",
      "item":"{dede:field.arcurl/}"
     }
    ]
   },
   {
    "@type": "BlogPosting",
    "headline": "{dede:field.title/}",
    "description": "{dede:field.description function='html2text(@me)'/}",
    "datePublished": "{dede:field.pubdate function='MyDate("Y-m-d\\TH:i:s",@me)'/}", //发布日期标准写法
    "dateModified": "{dede:field.pubdate function='MyDate("Y-m-d\\TH:i:s",@me)'/}",
    "inLanguage": "zh-CN",
    "author": {
     "@type": "Person",
     "name": "吖七(许祝岗)",
     "url": "{dede:global.cfg_basehost/}"
    },
    "publisher": {
     "@type": "Organization",
     "name": "{dede:global.cfg_webname/}",
     "url": "{dede:global.cfg_basehost/}/",
     "logo": {
      "@type": "ImageObject",
      "url": "{dede:global.cfg_basehost/}/images/logo.png"
     }
    },
    "image": "{dede:field.litpic/}",
    "url": "{dede:field.arcurl/}",
    "mainEntityOfPage": {
     "@type": "WebPage",
     "@id": "{dede:field.arcurl/}"
    }
   }
  ]
 }
</script>

<!-- 关于我们结构化数据标记 -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "WebPage",
  "name": "{dede:field.typename/}",
  "url": "{dede:type}[field:typeurl/]{/dede:type}",
  "publisher": {
    "@type": "Organization",
    "name": "吖七(许祝岗)"
  }
}
</script>

WordPress 机械设备类 Schema 设置

机械设备类主要有首页、产品页面、FAQ 问答页面、新闻资讯页面、关于我们页面。可以用 WordPress 的 ACF 把“自行修改”做成自定义字段,方面管理。以下 Schema 代码加到公共头部模板 header.php 的 </head> 之前,需要判断当前页面

<?php if (is_front_page()) { ?>
<!-- 首页结构化数据标记 -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Corporation",
  "name": "重庆XX", //网站名称,自行修改
  "url": "<?php echo home_url(); ?>/", //首页链接,后面又“/”,自行修改
  "logo": "/skin/images/logo.png", //网站logo路径,自行修改
  "description": "重庆XX描述……",  //网站描述,自行修改
  "contactPoint": {
        "@type": "ContactPoint",
        "telephone": "13883789255", //联系电话,自行修改
        "contactType": "customer service",
        "email": "570521548@qq.com",  //邮箱,自行修改
        "availableLanguage": "Chinese"
    }
}
</script>
<?php }elseif (is_category(1)){?>
//判断条件:普通分类页面,ID=1
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "CollectionPage",
  "name": "<?php echo single_cat_title('', false); ?> - <?php echo get_bloginfo('name'); ?>",
  "description": "<?php echo preg_replace('/\s+/', ' ', trim(strip_tags(category_description()))); ?>",
  "url": "<?php echo get_category_link(get_queried_object_id()); ?>",
  "publisher": {
   "@type": "Organization",
   "name": "重庆XX",  //网站名称,自行修改
   "url": "https://www.cqzmt.cn",
   "logo": {
    "@type":"ImageObject",
    "url": "/skin/images/logo.png"
    }
  }
}
</script>

<?php }elseif (is_category(3)){?>
//判断条件:FAQ分类页面,ID=3
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "FAQPage",
  "mainEntity": [
   //以下是把正文的问题(h2)内容提取出来作为小标题
   <?php
    global $wp_query;
    $cat_ID = get_query_var('cat');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts('cat='.$cat_ID.'&posts_per_page=5&paged='.$paged);
    $wp_query->is_archive = true;
    $wp_query->is_home = false;    
    $i = 0;
    while (have_posts()) : the_post();
    $i++;
    $content = get_the_content();
    preg_match_all('/<h2.*?>(.*?)<\/h2>/is', $content, $matches);
    $answer_text = '';      
    if (!empty($matches[1])) {
     $index = 1;
     foreach ($matches[1] as $h2) {
      $h2_clean = trim(strip_tags($h2));
      $h2_clean = preg_replace('/^[一二三四五六七八九十\d]+[.、\s]+/u', '', $h2_clean);
      $h2_clean = trim($h2_clean);              
      if (!empty($h2_clean)) {  //判断页面h2不为空
       $answer_text .= $index . '. ' . $h2_clean . ' ';
       $index++;
      }
     }
    }       
    $answer_text = trim($answer_text);
    $post_title = get_the_title();      
    $answer_text = json_encode($answer_text, JSON_UNESCAPED_UNICODE);
    $post_title = json_encode($post_title, JSON_UNESCAPED_UNICODE);
   ?>
  {
    "@type": "Question",
    "name": <?php echo $post_title; ?>,
    "acceptedAnswer": {
     "@type": "Answer",
     "text": <?php echo $answer_text; ?>
    }
   }
   <?php if($i < $wp_query->post_count) echo ','; ?><?php endwhile; wp_reset_query(); ?>
 ]
}
</script>
<?php } elseif (is_page() || is_category() || is_archive()) { ?>
//判断条件:普通页面(关于我们、联系我们等)
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "WebPage",
  "name": "<?php echo esc_attr(get_the_title()); ?> - 重庆XX",  //网站名称,自行修改
  "url": "<?php echo esc_url(get_permalink()); ?>",
  "publisher": {
    "@type": "Organization",
    "name": "重庆XX" //网站名称,自行修改
  }
}
</script>
<?php } elseif(is_singular()){;?>
//判断条件:普通文章、资讯、案例内容页面
<script type="application/ld+json">
{
    "@context": "https://schema.org",
    "@type": "Article",
    "headline": "<?php the_title(); ?>",
    "datePublished": "<?php the_time('Y-m-d H:m:s'); ?>",
    "dateModified": "<?php the_time('Y-m-d H:m:s'); ?>",
    "mainEntityOfPage": {
     "@type": "WebPage",
     "@id": "<?php the_permalink(); ?>"
    },
    "publisher": {
     "@type": "Organization",
     "name": "重庆XX",  //自行修改
     "logo": {
      "@type": "ImageObject",
      "url": "/skin/images/logo.png"  //自行修改
     }
    }
}
</script>
<?php }?>

这是 WordPress 比较简单的 Schema 写法,还有很多复杂的写法,就不展开了。对于企业网站来说被 AI 引用的一般只有首页、FAQ、产品、关于我们页,没必要过于复杂。网上说一些 WP 插件可以实现,但 FAQ 调用的是通用描述,按照我的写法更好:单独提取H2标签的内容作为描述,如:

1. 小标题一 2. 小标题二 3. 小标题三

    扩展阅读

    本文地址:https://www.vi586.com/geo/870.html
    版权声明:本文是吖七(许祝岗)原创,文中无商业推广,内容仅供参考,欢迎分享本文,转载请保留出处!