不知道更新啥了,就随便更新了

关于小编这个网站修改时的觉得还算有用的一点代码

小编偶的网站基本上是成型了,当然原来的主题作者也不对这款主题更新了,所以小编自己修改了一下,具体说修改不如说是抄袭更准确。嘿嘿,由于小编使用的是WordPress主题,主题采用Div+CSS布局,所以通过双内核浏览器的查看元素功能还是能轻易获取别人的样式代码的。
基本上小编使用了一下几个,高手可以绕行
[newcode title=”更换头像获取来源”]
function mytheme_get_avatar($avatar) {
$avatar = str_replace(array(“www.gravatar.com”,”0.gravatar.com”,”1.gravatar.com”,”2.gravatar.com”),”gravatar.duoshuo.com”,$avatar);
return $avatar;
}
add_filter( ‘get_avatar’, ‘mytheme_get_avatar’, 10, 3 );
[/newcode]
[newcode title=”//br标签不过滤”]
remove_filter( ‘the_content’, ‘wpautop’ );
add_filter( ‘the_content’, ‘wpautop’ , 12);
[/newcode]
[newcode title=”//谷歌字体移除”]<a href=”http://www.yanjingnan.cn/google-fonts-wordpress.html”>//谷歌字体移除</a>[/newcode]
[newcode title=”面包屑”]/* breadcrumbs nav */
function dimox_breadcrumbs() {
$delimiter = ‘»’;
$name = ‘眼镜男首页’; //text for the ‘Home’ link
$currentBefore = ”;
$currentAfter = ”;
if ( !is_home() &amp;&amp; !is_front_page() || is_paged() ) {
echo ‘
<ul>
<li id=”crumbs”>’;
global $post;
$home = get_bloginfo(‘url’);
echo ‘所在位置:<a href=”‘ . $home . ‘”>’ . $name . ‘</a> ‘ . $delimiter . ‘ ‘;
if ( is_category() ) {
global $wp_query;
$cat_obj = $wp_query-&gt;get_queried_object();
$thisCat = $cat_obj-&gt;term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat-&gt;parent);
if ($thisCat-&gt;parent != 0) echo(get_category_parents($parentCat, TRUE, ‘ ‘ . $delimiter . ‘ ‘));
echo $currentBefore . ‘Archive by category ”;
single_cat_title();
echo ”’ . $currentAfter;
} elseif ( is_day() ) {
echo ‘<a href=”‘ . get_year_link(get_the_time(‘Y’)) . ‘”>’ . get_the_time(‘Y’) . ‘</a> ‘ . $delimiter . ‘ ‘;
echo ‘<a href=”‘ . get_month_link(get_the_time(‘Y’),get_the_time(‘m’)) . ‘”>’ . get_the_time(‘F’) . ‘</a> ‘ . $delimiter . ‘ ‘;
echo $currentBefore . get_the_time(‘d’) . $currentAfter;
} elseif ( is_month() ) {
echo ‘<a href=”‘ . get_year_link(get_the_time(‘Y’)) . ‘”>’ . get_the_time(‘Y’) . ‘</a> ‘ . $delimiter . ‘ ‘;
echo $currentBefore . get_the_time(‘F’) . $currentAfter;
} elseif ( is_year() ) {
echo $currentBefore . get_the_time(‘Y’) . $currentAfter;
} elseif ( is_single() ) {
$cat = get_the_category(); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ‘ ‘ . $delimiter . ‘ ‘);
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_page() &amp;&amp; !$post-&gt;post_parent ) {
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_page() &amp;&amp; $post-&gt;post_parent ) {
$parent_id = $post-&gt;post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = ‘<a href=”‘ . get_permalink($page-&gt;ID) . ‘”>’ . get_the_title($page-&gt;ID) . ‘</a>’;
$parent_id = $page-&gt;post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ‘ ‘ . $delimiter . ‘ ‘;
echo $currentBefore;
the_title();
echo $currentAfter;
} elseif ( is_search() ) {
echo $currentBefore . ‘Search results for ” . get_search_query() . ”’ . $currentAfter;
} elseif ( is_tag() ) {
echo $currentBefore . ‘Posts tagged ”;
single_tag_title();
echo ”’ . $currentAfter;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $currentBefore . ‘Articles posted by ‘ . $userdata-&gt;display_name . $currentAfter;
} elseif ( is_404() ) {
echo $currentBefore . ‘Error 404’ . $currentAfter;
}
if ( get_query_var(‘paged’) ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ‘ (‘;
echo __(‘Page’) . ‘ ‘ . get_query_var(‘paged’);
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ‘)’;
}
echo ‘</li>
</ul>
&nbsp;

‘;
}
}//End: breadcrumbs[/newcode]
[newcode title=”自动添加关键字超链接”]$match_num_from = 1; //一篇文章中同一个关键字少于多少不秒文本(这个直接填1就好了)
$match_num_to = 2; //一篇文章中同一个关键字最多出现多少次描文本(建议不超过2次)
//连接到WordPress的模块
add_filter(‘the_content’,’tag_link’,1);
//按长度排序
function tag_sort($a, $b){
if ( $a-&gt;name == $b-&gt;name ) return 0;
return ( strlen($a-&gt;name) &gt; strlen($b-&gt;name) ) ? -1 : 1;
}
//改变标签关键字
function tag_link($content){
global $match_num_from,$match_num_to;
$posttags = get_the_tags();
if ($posttags) {
usort($posttags, “tag_sort”);
foreach($posttags as $tag) {
$link = get_tag_link($tag-&gt;term_id);
$keyword = $tag-&gt;name;
//连接代码
$cleankeyword = stripslashes($keyword);
$url = “<a title=”\&quot;&quot;.str_replace(‘%s’,addcslashes($cleankeyword,” href=”\&quot;$link\&quot;” target=”_blank”>”.addcslashes($cleankeyword, ‘$’).”</a>”;
$limit = rand($match_num_from,$match_num_to);
//不连接的 代码
$content = preg_replace( ‘|(&lt;a[^&gt;]+&gt;)(.*)(‘.$ex_word.’)(.*)(]*&gt;)|U’.$case, ‘$1$2%&amp;&amp;&amp;&amp;&amp;%$4$5’, $content);
$content = preg_replace( ‘|(&lt;img)(.*?)(‘.$ex_word.’)(.*?)(&gt;)|U’.$case, ‘$1$2%&amp;&amp;&amp;&amp;&amp;%$4$5’, $content);
$cleankeyword = preg_quote($cleankeyword,’\”);
$regEx = ‘\'(?!((&lt;.*?)|(&lt;a.*?)))(‘. $cleankeyword . ‘)(?!(([^&lt;&gt;]*?)&gt;)|([^&gt;]*?))\’s’ . $case;
$content = preg_replace($regEx,$url,$content,$limit);
$content = str_replace( ‘%&amp;&amp;&amp;&amp;&amp;%’, stripslashes($ex_word), $content);
}
}
return $content;
}
add_filter( ‘pre_option_link_manager_enabled’, ‘__return_true’ );
[/newcode]
[newcode title=”关于缩略图【七牛加防盗链情况】”]function post_thumbnail( $width = 160,$height = 125 ){
global $post;
if( has_post_thumbnail() ){
$timthumb_src = wp_get_attachment_image_src(get_post_thumbnail_id($post-&gt;ID),’full’);
$post_timthumb = ‘<img src=”.$timthumb_src[0].” alt=”&quot;’.$post-” />post_title.'” class=”thumb” /&gt;’;
echo $post_timthumb;
} else {
$content = $post-&gt;post_content;
preg_match_all(‘/&lt;img.*?(?: |\\t|\\r|\\n)?src=[\'”]?(.+?)[\'”]?(?:(?: |\\t|\\r|\\n)+.*?)?&gt;/sim’, $content, $strResult, PREG_PATTERN_ORDER);
$n = count($strResult[1]);
if($n &gt; 0){
$post_img_src=$strResult[1][0];
} else {
$post_img_src=get_bloginfo(‘template_url’).’/images/random/’.rand(1,10).’.jpg’;
}
}
$post_img = mirana_image_strategy($post_img_src, $width, $height);//$post_img_src必须为
$post_img = sprintf(“<img src=”%s” alt=”%s” width=”%d” height=”%d” />”, $post_img, $title, $width, $height);
echo ‘<a href=”‘.get_permalink().'”>’.$post_img.'</a>’;
}

function mirana_image_strategy($url, $width, $height){
preg_match(‘/[\w][\w-]*\.(?:com\.cn|com|cn|co|net|org|gov|cc|biz|info)(\/|$)/isU’, $url, $domain);//获取一级域名
$user_qiniu=rtrim($domain[0], ‘/’);
if( $user_qiniu ==”qiniudn.com”){
$url =$url.”-yjn”;
}else{
$url = get_option(‘siteurl’).”/wp-content/themes/Mossight/timthumb.php?src={$url}&amp;w={$width}&amp;h={$height}&amp;zc=1&amp;q=100″;
}
return $url;
}[/newcode]
[newcode title=” //站外域nofollow”]add_filter(‘the_content’,’the_content_nofollow’,999);
function the_content_nofollow($content){
preg_match_all(‘/href=”(.*?)”/’,$content,$matches);
if($matches){
foreach($matches[1] as $val){
if( strpos($val,home_url())===false ) $content=str_replace(“href=\”$val\””, “href=\”$val\” rel=\”external nofollow\” “,$content);
}
}
return $content;
}[/newcode][newcode title=”本文作者”]

<div class=”articles”>
<div class=”post-author”>
<div class=”avatar1″><?php echo get_avatar( get_the_author_email(), ’70’ ); ?></div>
<div class=”post-author-desc”>
<div class=”post-author-name” ><?php the_author_posts_link(); ?>(猛击看专栏)<span class=”post-author-about”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php the_author_firstname(); ?> </span></div>

<div class=”post-author-description”><?php echo the_author_meta( ‘description’ ); ?></div>
<div class=”post-author-links”>本小编已发表<?php the_author_posts();?>篇文章<?php if (get_the_author_meta(‘weibo_sina’)!=””){ ?><?php echo “<a href='” . get_the_author_meta(‘weibo_sina’) . “‘ target=’_blank’ rel=’nofollow’> | 新浪微博</a>”; ?><?php } ?><?php if (get_the_author_meta(‘weibo_tx’)!=””){ ?><?php echo “<a rel=’nofollow’ href='” . get_the_author_meta(‘weibo_tx’) . “‘ target=’_blank’> | 腾讯微博</a>”; ?><?php } ?><?php if (get_the_author_meta(‘renren’)!=””){ ?><?php echo “<a rel=’nofollow’ href='” . get_the_author_meta(‘renren’) . “‘ target=’_blank’> | 人人</a>”; ?><?php } ?><?php if (get_the_author_meta(‘user_url’)!=””){ ?><?php echo “<a rel=’nofollow’ href='” . get_the_author_meta(‘user_url’) . “‘ target=’_blank’> | TA的一亩三分地</a>”; ?><?php } ?></div>
<div class=”clear” style=”clear both”></div>
<div class=”post-author-title”>本文小编</div>
</div>
</div>
</div>
//CSS


.articles {float: right;width: 640px;padding: 10px 0 10px 0;overflow: hidden;}
.entry-meta{overflow:hidden;clear:both;width:100%;line-height:22px;font-size:12px!important;margin-top:10px;}.entry-meta ul{overflow:hidden;margin:8px 0 10px 0;padding:8px 0 10px 15px;border:1px solid #DEDEDE;border-radius:3px;-webkit-border-radius:3px;background:#F9F9F9;}.entry-meta ul li{line-height:22px;}.entry-meta a a:hover{color:#0086E3 !important}#sidebar a{color:#3c3c3c}
[/newcode]

仿异次元下载页面

[newcode title=”非本站文章访问下载页面js跳转到原文页面”]<script type=”text/javascript”>// <![CDATA[
if(self!=top){top.location=self.location;}
var ref=document.referrer;
var domains=new Array(“huisexi.com/”,”yanjingnan.cn/”);//这里面写你自己的域名
var refpass=false;
for(i=0;i<=domains.length;i++){if(ref.indexOf(domains[i])>0){refpass=true;break;}}
if(ref==””){refpass=true}
if(!refpass){window.location.href='<?php function the_slug() { $post_data = get_post($post->ID, ARRAY_A);
$slug = $post_data[‘post_name’];//别名
$dizuozhe = $post_data[‘post_author’];//作者[id]
switch($dizuozhe){
//根据作者id判断原文地址域名
case 1:
$wzlysite=”http://www.yanjingnan.cn/”;
return $wzlysite.$slug;
case 2:
$wzlysite=”http://www.huisexi.com/”;
return $wzlysite.$slug;
}
}
function link_url(){
$jsurl=the_slug().”.html”;//原文地址
return $jsurl;
}
echo link_url();
?>’;}
// ]]></script>[/newcode]

关于主机的选择,大家可以看这里

赞(0) 打赏
未经允许不得转载:枣庄滕州微信小程序开发_wordpress主机SEO优化_滕州网站建设 -眼镜男网络 » 关于小编这个网站修改时的觉得还算有用的一点代码
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

'); })();