很早之前看到macdang.com的时候,觉得这套模板很清新,比较适合coder做自己的技术博客,想把自己的博客模板也换成这个。可惜查看相关代码没有找到模板作者。昨天查看wopus的时候看到了这套模板: 原名为M2模板。作者通过最wordpress源生php代码实现了翻页,阅读计数等常见插件的功能,不过对于seo这一块并没有做,这里补充下实现wordpress 源生代码实现Seo .
以下代码替换模板代码 header.php中
<?php if (is_home ()) { $keywords = "相关关键字描述"; $description = "相关desc描述"; } elseif (is_single ()) { if ($post->post_excerpt) { $description = $post->post_excerpt; } else { $str = csubstr ( strip_tags ( $post->post_content ), 0, 220 ); $str = trim ( $str ); $str = strip_tags ( $str, "" ); $str = ereg_replace ( "\t", "", $str ); $str = ereg_replace ( "\r\n", "", $str ); $str = ereg_replace ( "\r", "", $str ); $str = ereg_replace ( "\n", "", $str ); $str = ereg_replace ( " ", " ", $str ); $description = trim ( $str ); } $keywords = ""; $tags = wp_get_post_tags ( $post->ID ); foreach ( $tags as $tag ) { $keywords = $keywords . $tag->name . ", "; } } ?> <title><?php global $page, $paged; wp_title ( '|', true, 'right' ); bloginfo ( 'name' ); $site_description = get_bloginfo ( 'description', 'display' ); if ($site_description && (is_home () || is_front_page ())) echo " | $site_description"; if ($paged >= 2 || $page >= 2) echo ' | ' . sprintf ( __ ( 'Page %s' ), max ( $paged, $page ) ); ?></title> <meta name="keywords" content="<?=$keywords?>" /> <meta name="description" content="<?=$description?>" /> function csubstr($str, $start=0, $length, $charset="utf-8", $suffix=true){ if(function_exists("mb_substr")) return mb_substr($str, $start, $length, $charset); $re['utf-8'] = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/"; $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/"; $re['gbk'] = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/"; $re['big5'] = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/"; preg_match_all($re[$charset], $str, $match); $slice = join("",array_slice($match[0], $start, $length)); if($suffix) return $slice."¡"; }
本文资料:
www.macdang.com mac党 主要是下载破解mac软件的,目前已经不怎么更新 www.mangguo.org m2 主题作者