一.如何开发百度小程序的TDK标签和同步关键词这些呢?
下面请看我的方法
1.首先要确保TDK标签实现动态化同步,也就是标题,描述,关键词要同步帝国CMS后台网站的文章标题,文章描述,文章关键词,所以在帝国CMS后台发布文章的时候一定要设置标题,关键词,描述,这样才有利于百度小程序关键词权重的提升。
2.百度小程序页面开发TDK标签也就是百度的onShow里的swan.setPageInfo方法,动态同步后端接口请求来的数据。
3.百度小程序页面的方法开发好后,我们需要帝国CMS后端API接口里输出title,keywords,smalltext这些字段确保百度小程序能正常接收动态同步这些数据: 自己有接口可以不用哈,这里先显示出来自己看着用。swan.setPageInfo({
title: this.title,
keywords: this.keywords,
description: this.description,
success: function() {
console.log('setPageInfo success');
},
fail: function(err) {
console.log('setPageInfo fail', err);
}
})
});
<?php
header("Content-Type:application/json;charset=UTF-8");
require(dirname(__DIR__) . '/e/class/connect.php');
require(ECMS_PATH . '/e/class/EmpireCMS_version.php');
require(ECMS_PATH . '/e/class/db_sql.php');
$link=db_connect(); //连接MYSQL
$empire=new mysqlquery(); //声明数据库操作类
$editor=1; //声明目录层次
$aid = $_REQUEST['id'];
$sql = $empire->query("select a.id,a.title,a.keyboard,a.smalltext,a.newstime,a.editor,addon.newstext, from {$dbtbpre}ecms_news a left join {$dbtbpre}ecms_news_data_1 addon on addon.id=a.id where a.id='$aid'");
while ($row=$empire->fetch($sql)){
$body=str_replace('\\','',$html);
$data[]=array(
'id'=>$row['id'],
'title'=>$row['title'],
'keywords'=>$row['keyboard'],
'smalltext'=>$row['smalltext'],
'newstext'=> $body
);
}
二.如何实现帝国CMS百度小程序的文章自动化收录
1.进入百度小程序后台点自然搜索,然后点小程序新资源提交-自动同步-添加索引页,索引页就是小程序的索引页面/pages/swan-sitemap/index
2.百度小程序之帝国CMS索引页的开发,首先我们帝国CMS后端需要写一个自动化收录的百度小程序索引页接口,接口代码如下:放到根目录下即可,路径要填写对哦尤其是第三行的这个路径,这里做个备注吧万一帝国的你不会了拿来做参考,<?php
header("Content-Type:application/json;charset=UTF-8");
require(dirname(__DIR__) . '/e/class/connect.php');
require(ECMS_PATH . '/e/class/EmpireCMS_version.php');
require(ECMS_PATH . '/e/class/db_sql.php');
$link=db_connect(); //连接MYSQL
$empire=new mysqlquery(); //声明数据库操作类
$editor=1; //声明目录层次
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 0; //获取当前页码 没有的话 就是错误提示
if($page==0) die("error: Not found!");
$pageSize=100;//每页100条
$classid = $_REQUEST['classid'];
$year = $_REQUEST['year'];
$month = $_REQUEST['month'];
$totalquery = "select count(*) as total from {$dbtbpre}ecms_news";
$num = $empire->gettotal($totalquery);
$sql = $empire->query("select * from {$dbtbpre}ecms_news order by newstime desc limit $start,$pageSize");
$pages = ceil($num / $pageSize);
$listdata = array();
while ($row=$empire->fetch($sql)){
// Array<{title:string, path:string, releaseDate:DateString}>,详见下节 “list-data 项格式说明”
$listdata[]=array(
'title'=>$row['title'],
'path'=>'/pages/detail/detail?id='.$row['id'],
'releaseDate'=>date("Y-m-d H:i:s",$row['newstime'])
);
}
echo json_encode(array('pages'=>$pages,'num'=>$num,'list'=>$listdata));
db_close();
$empire=null;
?>
建议用下面这个,因为这个是改完后的版本百分百可用放根目录下的接口代码改良版:
<?php
header("Content-Type:application/json;charset=UTF-8");
require ('e/class/connect.php');
require(ECMS_PATH . '/e/class/EmpireCMS_version.php');
require(ECMS_PATH . '/e/class/db_sql.php');
$link=db_connect();
$empire=new mysqlquery();
$editor=1; //声明目录层次
$page = isset($_REQUEST['page']) ? $_REQUEST['page'] : 0;
// echo $page;
if($page==0) die("error: Not found!");
$pageSize=30;//每页100条
$page1 = ($page-1)*$pageSize;
$classid = $_REQUEST['classid'];
$year = $_REQUEST['year'];
$month = $_REQUEST['month'];
$totalquery = "select count(*) as total from {$dbtbpre}ecms_news";
$num = $empire->gettotal($totalquery);
// $sql = $empire->query("select * from {$dbtbpre}ecms_news order by newstime desc limit $start,$pageSize");
$sql = $empire->query("select * from {$dbtbpre}ecms_news order by newstime desc limit $page1,$pageSize");
$pages = ceil($num / $pageSize);
$listdata = array();
while ($row=$empire->fetch($sql)){
// Array<{title:string, path:string, releaseDate:DateString}>,详见下节 “list-data 项格式说明”
$listdata[]=array(
'title'=>$row['title'],
'path'=>'/pages/neirong/index?classid='.$row['classid'].'&id='.$row['id'],
'releaseDate'=>date("Y-m-d H:i:s",$row['newstime'])
);
}
// print_r($listdata);exit();
echo json_encode(array('pages'=>$pages,'num'=>$num,'list'=>$listdata));
db_close();
$empire=null;
?>
3.索引页接口写好后,我们在百度小程序页面,这个页面我们命名为swan-sitemap/index进行索引页数据对接。这样百度小程序就会自动同步抓取收录了。
<swan-sitemap-list
list-data="{{listData}}"
current-page="{{currentPage}}"
total-page="{{totalPage}}"
path="/swan-sitemap/index">
</swan-sitemap-list>