一些博客,特别是一些国外的博客都用FeedBurner的chicklet来显示订阅数量,如果你想在你的博客上显示最近7天的平均订阅量,以下代码可以实现。
首先要做的是把以下代码添加到function.php文件中:
- function get_average_readers($feed_id,$interval = 7){
- $today = date('Y-m-d', strtotime("now"));
- $ago = date('Y-m-d', strtotime("-".$interval." days"));
- $feed_url="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=".$feed_id."&dates=".$ago.",".$today;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_URL, $feed_url);
- $data = curl_exec($ch);
- curl_close($ch);
- $xml = new SimpleXMLElement($data);
- $fb = $xml->feed->entry['circulation'];
-
- $nb = 0;
- foreach($xml->feed->children() as $circ){
- $nb += $circ['circulation'];
- }
-
- return round($nb/$interval);
- }
阅读全文…
将以下代码复制粘贴到functions.php,你的WordPress博客rss feed 中将显示你博客中图片的缩略图。
- function diw_post_thumbnail_feeds($content) {
- global $post;
- if(has_post_thumbnail($post->ID)) {
- $content = '
- <div>' . get_the_post_thumbnail($post->ID) . '</div>
- ' . $content;
- }
- return $content;
- }
- add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds');
- add_filter('the_content_feed', 'diw_post_thumbnail_feeds');
这篇文章是一个关于“WordPress的黑客”的文章。
如果你喜欢的,你一定会喜欢这一个。 这里有10个,看下面的:
1. 多种浏览器兼容你的WordPress主题
在设计一个主题,有很多跨浏览器的兼容性问题,提高他们的头,大多数我们别无选择,只有恢复到使用条件黑客留下倍。 -下面的WordPress的黑客真的可以节省很多头痛: -
打开的主题文件夹您的functions.php文件,并添加以下代码:
< ?php
add_filter('body_class','browser_body_class');
function browser_body_class($classes) {
global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;
*//上面的函数将浏览器的名称(如,opera,safari等),您的这样的标记:/
if($is_lynx) $classes[] = 'lynx';
elseif($is_gecko) $classes[] = 'gecko';
elseif($is_opera) $classes[] = 'opera';
elseif($is_NS4) $classes[] = 'ns4';
elseif($is_safari) $classes[] = 'safari';
elseif($is_chrome) $classes[] = 'chrome';
elseif($is_IE) $classes[] = 'ie';
else $classes[] = 'unknown';
if($is_iphone) $classes[] = 'iphone';
return $classes;
}
?>
现在,你作为一个主题设计可以帮助这个自定义类,并相应地写你的CSS,如果你所面对的任何浏览器的兼容性问题。 这可以说是提前 “作为” 计划 !
阅读全文…
如果你的博客上由几人负责更新发布或者写作的,那么你一定可以用得到这个WordPress hack。当然一个人的也上有用的。
把博文的作者的信息添加到博文某处,不仅可以宣传作者,同时,浏览者也能看到更多的信息,具有更大的粘性。
下面还是来说怎么办吧!
首先,打开functions.php,复制和粘贴以下代码:
function get_author_bio ($content=”){
global $post;
$post_author_name=get_the_author_meta(“display_name”);
$post_author_description=get_the_author_meta(“description”);
$html=”<div class=’clearfix’ id=’about_author’>\n”;
$html.=”<img width=’80′ height=’80′ class=’avatar’ src=’http://www.gravatar.com/avatar.php?gravatar_id=”.md5(get_the_author_email()). “&default=”.urlencode($GLOBALS['defaultgravatar']).”&size=80&r=PG’ alt=’PG’/>\n”;
$html.=”<div class=’author_text’>\n”;
$html.=”<h4>Author: <span>”.$post_author_name.”</span></h4>\n”;
$html.= $post_author_description.”\n”;
$html.=”</div>\n”;
$html.=”<div class=’clear’></div>\n”;
$content .= $html;
}
return $content;
}
add_filter(‘the_content’, ‘get_author_bio’);
接下来在你的模板里调用设定的函数即可。
注:其实还有另外的实现方法,飞鱼的声纳采用的上在Users > Your Profile添加完全信息,然后在single.php中插入使用
调用,详细情况可以去飞鱼的声纳看一看
编译:博客海
原文地址:wprecipes
最新评论