Typecho模板设置数据会在你换模板的时候被清空,这样的设置其实我还是蛮喜欢的,不会有数据残留。
但是有些朋友可能会希望保留数据,这样下次在切换回来之后数据就保留了。

//备份开始
$db = Typecho_Db::get();
$sjdq=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:splity'));
$ysj = $sjdq['value'];
if(isset($_POST['type']))
{ 
if($_POST["type"]=="备份模板数据"){
if($db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:splitybf'))){
$update = $db->update('table.options')->rows(array('value'=>$ysj))->where('name = ?', 'theme:splitybf');
$updateRows= $db->query($update);
echo '
备份已更新,请等待自动刷新!如果等不到请点击'; ?> 这里
insert('table.options') ->rows(array('name' => 'theme:splitybf','user' => '0','value' => $ysj)); $insertId = $db->query($insert); echo '
备份完成,请等待自动刷新!如果等不到请点击'; ?> 这里
fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:splitybf'))){ $sjdub=$db->fetchRow($db->select()->from ('table.options')->where ('name = ?', 'theme:splitybf')); $bsj = $sjdub['value']; $update = $db->update('table.options')->rows(array('value'=>$bsj))->where('name = ?', 'theme:splity'); $updateRows= $db->query($update); echo '
检测到模板备份数据,恢复完成,请等待自动刷新!如果等不到请点击'; ?> 这里
没有模板备份数据,恢复不了哦!