之前emlog和wordpress都可以直接使用插件来实现文章列表页面,但是typecho并没有这个功能,这个和sitemap是不一样的。
页面效果
这个用处是什么?
也许有人会问这个有什么用,都有sitemap了,这个是干嘛的。
首先sitemap的格式是这样的,主要就是表明了文章的链接、更新时间等信息,在百度后台、谷歌后台都可以提交,等着搜索引擎来抓取。
而搜索引擎还有一个功能是自己主动提交。提交的格式就是一行一个链接,或者一行一个链接的文件。这个列表的链接就是为了做这个用的。
制作模板页面
typecho在后台可以根据模板创建自定义页面,这里就是创建一个自定义模板,里面的功能就是在数据库中找出所有的文章链接并且提取输出出来,新建一个文件URLLinks.php
,内容写以下内容。
<?php
/**
* 网站链接列表
*
* @package custom
*
*/
?>
<?php
$db = Typecho_Db::get();
$options = Typecho_Widget::widget('Widget_Options');
$posts= $db->fetchAll($db->select()->from('table.contents')
->where('table.contents.status = ?', 'publish')
->order('table.contents.created', Typecho_Db::SORT_DESC));
foreach($posts as $p)
{
/** 取出所有分类 */
$p['categories'] = $db->fetchAll($db
->select()->from('table.metas')
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
->where('table.relationships.cid = ?', $p['cid'])
->where('table.metas.type = ?', 'category')
->order('table.metas.order', Typecho_Db::SORT_ASC));
/** 取出第一个分类作为slug条件 */
$p['category'] = current(Typecho_Common::arrayFlatten($p['categories'], 'slug'));
//去掉附件
$type = $p['type'];
if($type == "post"){
$routeExists = (NULL != Typecho_Router::get($type));
$pathinfo = $routeExists ? Typecho_Router::url($type, $p) : '#';
$permalink = Typecho_Common::url($pathinfo, $options->index);
echo "<a href=\"".$permalink."\">".$permalink."</a><br/>";
}
}
?>
将文件上传到模板的根目录,然后去后台新建独立页面,在自定义模板中选择网站链接列表
这个模板就可以了。
当然这个创建出来的页面就是单纯的链接页面,为了更加好看,我们可以在这个页面的基础上完善下,当然不是必须的,如果想需要知道,可以往下看。
完善模板页面
首先可以使用<?php $this->need()?>
这个函数增加上页面的头部和底部,可以看模板文件夹里面的page.php文件是怎么加头部和底部的,因为不同的模板引入的路径不同,
然后将链接的布局位置微调一下更好看。
因为这个打印出来的是所有的链接,但是有时候提交的限额有限,所以可以每隔五十条将链接颜色修改为红色,在前端可以更直观。
完善后的模板页面URLLinks.php
代码如下,你可以比较下和上面的基础版的差别。
<?php
/**
* 网站链接列表
*
* @package custom
*
*/
?>
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('component/header.php'); ?>
<main class="app-content-body">
<div style="margin-bottom: 100px;
margin-left: 100px;
margin-top: 100px;">
<?php
$db = Typecho_Db::get();
$options = Typecho_Widget::widget('Widget_Options');
$posts= $db->fetchAll($db->select()->from('table.contents')
->where('table.contents.status = ?', 'publish')
->order('table.contents.created', Typecho_Db::SORT_DESC));
$boolHr = 0;
foreach($posts as $p)
{
/** 取出所有分类 */
$p['categories'] = $db->fetchAll($db
->select()->from('table.metas')
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
->where('table.relationships.cid = ?', $p['cid'])
->where('table.metas.type = ?', 'category')
->order('table.metas.order', Typecho_Db::SORT_ASC));
/** 取出第一个分类作为slug条件 */
$p['category'] = current(Typecho_Common::arrayFlatten($p['categories'], 'slug'));
//去掉附件
$type = $p['type'];
if($type == "post"){
$routeExists = (NULL != Typecho_Router::get($type));
$pathinfo = $routeExists ? Typecho_Router::url($type, $p) : '#';
$permalink = Typecho_Common::url($pathinfo, $options->index);
$boolHr++;
if($boolHr%50 == 0){
echo "<font size=\"3\" color=\"red\"><a href=\"".$permalink."\">".$permalink."</a></font><br/>";
}
else{
echo "<a href=\"".$permalink."\">".$permalink."</a><br/>";
}
}
}
?>
</div>
</main>
<!-- footer -->
<?php $this->need('component/footer.php'); ?>
<!-- / footer -->
链接提交到搜索引擎
通过模板创建好对应的页面之后,就可以访问那个页面了,那个页面的内容就是所有的链接列表。这时候就可以复制这些链接去搜索引擎的后台提交了,比如百度。去百度的搜索资源平台:http://ziyuan.baidu.com/,验证完网站的所有权之后,有一个链接提交的功能。
后台提交
如果你是基础使用,那么可以将这些链接直接粘贴到提交框,然后去提交就行了。
使用curl推送
这种使用脚本推送的就更简单了,在桌面新建一个文件,命名为urls.txt,将这些链接复制进去,然后通过自己的推送接口使用命令行提交就行了。
参考链接
版权属于:胡东东博客
本文链接:https://blog.hudongdong.com/708.html
自2017年12月26日起,『转载以及大段采集进行后续编辑』须注明本文标题和链接!否则禁止所有转载和采集行为!
3 comments
感谢分享
请问你网站的sitemap.xml用的什么插件?
caixw做的sitemap