存档

文章标签 ‘WordPress hack’

怎样显示博客feed平均订阅阅读数

2010年8月22日 没有评论

一些博客,特别是一些国外的博客都用FeedBurner的chicklet来显示订阅数量,如果你想在你的博客上显示最近7天的平均订阅量,以下代码可以实现。

首先要做的是把以下代码添加到function.php文件中:

  1. function get_average_readers($feed_id,$interval = 7){
  2. $today = date('Y-m-d', strtotime("now"));
  3. $ago = date('Y-m-d', strtotime("-".$interval." days"));
  4. $feed_url="https://feedburner.google.com/api/awareness/1.0/GetFeedData?uri=".$feed_id."&dates=".$ago.",".$today;
  5. $ch = curl_init();
  6. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  7. curl_setopt($ch, CURLOPT_URL, $feed_url);
  8. $data = curl_exec($ch);
  9. curl_close($ch);
  10. $xml = new SimpleXMLElement($data);
  11. $fb = $xml->feed->entry['circulation'];
  12.  
  13. $nb = 0;
  14. foreach($xml->feed->children() as $circ){
  15. $nb += $circ['circulation'];
  16. }
  17.  
  18. return round($nb/$interval);
  19. }

阅读全文…

WordPress Hack:在RSS Feed中显示缩略图

2010年6月24日 33 条评论

将以下代码复制粘贴到functions.php,你的WordPress博客rss feed 中将显示你博客中图片的缩略图。

  1. function diw_post_thumbnail_feeds($content) {
  2. global $post;
  3. if(has_post_thumbnail($post->ID)) {
  4. $content = '
  5. <div>' . get_the_post_thumbnail($post-&gt;ID) . '</div>
  6. ' . $content;
  7. }
  8. return $content;
  9. }
  10. add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds');
  11. add_filter('the_content_feed', 'diw_post_thumbnail_feeds');

10+WordPress hack使你的WordPress博客更简单

2010年2月19日 4 条评论

这篇文章是一个关于“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:如何在每篇博文上加上作者的信息

2009年11月3日 3 条评论

如果你的博客上由几人负责更新发布或者写作的,那么你一定可以用得到这个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