• emlog代码实现seo优化


    1. <?php
    2. if(!defined('EMLOG_ROOT')) {exit('error!');}
    3. global $CACHE;
    4. $Have_Sort_Cache = $CACHE->readCache('sort');
    5. $Have_User_Cache = $CACHE->readCache('user');
    6. $Have_Options_Cache = $CACHE->readCache('options');
    7. $Have_Log_Cache_Tags = $CACHE->readCache('logtags');
    8. $Have_Log_Cache_Sort = $CACHE->readCache('logsort');
    9. $Log_Model = new Log_Model();
    10. if($type=='blog'){
    11. extract($Log_Model->neighborLog($timestamp));
    12. }
    13. $Body_Title = $Have_Options_Cache['site_title'] ? $Have_Options_Cache['site_title'] : $Have_Options_Cache['blogname'];
    14. if( $params[1]=='page' ){
    15. $Body_Page = '第'.htmlspecialchars(urldecode($params[2])).'页_';
    16. }
    17. if( $params[4]=='page' ){
    18. $Body_Page = '第'.htmlspecialchars(urldecode($params[5])).'页_';
    19. }
    20. if($tws){
    21. preg_match_all('|^.*/?(page)=(d+)([?&].*)?$|',Dispatcher::setPath(),$Preferred);
    22. $emDispatcher = Dispatcher::setPath();
    23. if( $Preferred[1][0]=='page' ){
    24. $Body_Page = '第'.htmlspecialchars(urldecode($Preferred[2][0])).'页_';
    25. }
    26. }
    27. if (!empty($Have_Log_Cache_Tags[$logid])) {
    28. foreach ($Have_Log_Cache_Tags[$logid] as $value) {
    29. $Have_Log_key .= $value['tagname'].',';
    30. }
    31. }
    32. if(!empty($Have_Log_Cache_Sort[$logid])){
    33. $Log_Sort_Name = $Have_Log_Cache_Sort[$logid]['name'];
    34. }
    35. if(empty($Have_Log_key)){
    36. $Log_KeyWords = stripslashes($Log_Sort_Name);
    37. }else{
    38. $Log_KeyWords = $Have_Log_key;
    39. }
    40. if( blog_tool_ishome() ){
    41. $web_title = $Have_Options_Cache['site_title'];
    42. $web_keywords = $Have_Options_Cache['site_key'];
    43. $web_description = $Have_Options_Cache['site_description'];
    44. }elseif( $params[1]=='sort' ){
    45. $web_title = $Have_Sort_Cache[$sortid]['sortname'].'_'.$Body_Page.$Body_Title;
    46. $web_keywords = $Have_Sort_Cache[$sortid]['sortname'];
    47. $web_description = $Have_Sort_Cache[$sortid]['description'];
    48. }elseif( $params[1]=='tag' ){
    49. $web_title = stripslashes($tag).'_'.$Body_Page.$Body_Title;
    50. $web_keywords = stripslashes($tag);
    51. $web_description = $Have_Options_Cache['blogname']."'".stripslashes($tag)."'";
    52. }elseif( $params[1]=='keyword' || $params[1]=='?keyword=' ){
    53. $web_title = '搜索结果 '.$keyword.'_'.$Body_Page.$Body_Title;
    54. $web_keywords = stripslashes($keyword);
    55. $web_description = $Have_Options_Cache['blogname'].": '".stripslashes($keyword)."' 的搜索結果";
    56. }elseif( $params[1]=='author' ){
    57. $web_title = $Have_User_Cache[$author]['name'].'_'.$Body_Page.$Body_Title;
    58. $web_keywords = $Have_User_Cache[$author]['name'];
    59. $web_description = $Have_Options_Cache['blogname']."'".$Have_User_Cache[$author]['name']."'";
    60. }elseif( $params[1]=='record' ){
    61. $web_title = stripslashes($params[2]).'_'.$Body_Page.$Body_Title;
    62. $web_keywords = stripslashes($params[2]);
    63. $web_description = $Have_Options_Cache['blogname'].": '".stripslashes($params[2])."' 的文章列表";
    64. }elseif( $type == 'blog' ){
    65. $web_title = stripslashes($log_title).'_'.$Body_Title;
    66. $web_keywords = $Log_KeyWords;
    67. $web_description = extractHtmlData($log_content, 90);
    68. if($prevLog){
    69. $web_prev = "<link rel='prev' title='{$prevLog['title']}' href='".Url::log($prevLog['gid'])."' />";
    70. }
    71. if($nextLog && $prevLog){
    72. }
    73. if($nextLog){
    74. $web_next = "<link rel='next' title='{$nextLog['title']}' href='".Url::log($nextLog['gid'])."' />";
    75. }
    76. $web_canonical = "<link rel='canonical' href='".URL::log($logid)."' />";
    77. $web_shortlink = "<link rel='shortlink' href='".BLOG_URL."?post={$logid}' />";
    78. }elseif( $type == 'page' ){
    79. $web_title = stripslashes($log_title).'_'.$Body_Title;
    80. $web_keywords = stripslashes($log_title);
    81. $web_description = extractHtmlData($log_content, 90);
    82. }elseif( $tws ){
    83. $web_title = '微语_'.$Body_Page.$Body_Title;
    84. $web_keywords = stripslashes($log_title);
    85. $web_description = extractHtmlData($log_content, 90);
    86. }
    87. echo "<title>{$web_title}</title> <meta name="generator" content="Emlog ".Option::EMLOG_VERSION."" />";
    88. if( $type == 'blog' ){
    89. if($prevLog){
    90. echo " ".$web_prev;
    91. }
    92. if($nextLog && $prevLog){
    93. }
    94. if($nextLog){
    95. echo " ".$web_next;
    96. }
    97. echo " ".$web_canonical." ".$web_shortlink;
    98. }
    99. echo " <meta name="keywords" content="{$web_keywords}" /> <meta name="description" content="{$web_description}" />";
    100. ?>

    之后再在模板的 header.php 当中加载此文件即可:require_once View::getView('breadcrumb-template');

    这样可以使博客的SEO得到较好的优化,emlog博客强烈推荐

  • 相关阅读:
    在Python下调用Labview
    CVX: Matlab Software for Disciplined Convex Programming
    ANSYS Electronics Desktop 调出HFSS模块
    在python下打开cmd,并调用其他py文件
    CVXOPT的安装
    分享小记:指数族分布
    应用运筹学基础:线性规划 (4)
    应用运筹学基础:线性规划 (3)
    应用运筹学基础:线性规划 (2)
    白话论文:A Tutorial on Principal Component Analysis
  • 原文地址:https://www.cnblogs.com/Ponlai/p/10138379.html
Copyright © 2020-2023  润新知