很多朋友已经开设了Google+帐号,并且也有自己的Wordpress Blog,如果你希望把Google+的更新内容及时的显示在你的Wordpress Blog上,你可以试试下面的几种方法。
一、不使用插件显示Google+的更新
把下面的代码复制到你希望显示的位置,记得将其中的个人ID替换成你自己的:
<?php include_once(ABSPATH.WPINC.'/rss.php'); $googleplus = fetch_feed("http://plusfeed.appspot.com/109252324503373128615"); // 将105370233753400230532替换成你自己的 echo '<a href="'; echo $googleplus->items[0]['link']; echo '">'; echo $googleplus->items[0]['summary']; echo ''; ?>
二、显示最新更新的5条Google+内容:
这段代码由 Nilesh Shiragave 提供,给你的 functions.php 增加了一个google_plus_feed 调用,然后你可以在你的模板文件中调用它了,可以修改 $items 实现每次获取的更新条数,将下面代码添加到你的 functions.php 文件:
function google_plus_feed($id,$items=5) { $feed='http://plusfeed.appspot.com/'.$id; include_once(ABSPATH.WPINC.'/rss.php'); $rss = fetch_feed($feed); if (!is_wp_error( $rss ) ) : // Checks that the object is created correctly // Figure out how many total items there are, but limit it to 5. $maxitems = $rss->get_item_quantity($items); // Build an array of all the items, starting with element 0 (first element). $rss_items = $rss->get_items(0, $maxitems); ?> <ul> <?php if ($maxitems == 0) echo '<li>No items.</li>'; else // Loop through each feed item and display each item as a hyperlink. foreach ( $rss_items as $item ) : ?> <li> <a href='<?php echo esc_url( $item->get_permalink() ); ?>' title=''> <?php echo esc_html( $item->get_title() ); ?></a> <small><?php echo 'Posted On'.$item->get_date('j F Y | g:i a'); ?></small> </li> <?php endforeach; ?> </ul> <?php endif; }
将下面代码添加到你的模板文件中,注意修改其中的ID数:
if(function_exists(‘google_plus_feed’))
{ google_plus_feed('109252324503373128615',5); /* Replace 105370233753400230532 with your google Plus ID */ }
三、使用Wordpress组件实现Google+的更新,下面是两个可用的组件:
1、My Google Plus Widget – 这个插件是基于官方API开发,不仅可以显示你自己的更新,也可以显示其他用户的更新。
2、Google+ Plus WordPress Widget – 显示你自己的Google+更新,并且可以修改显示的条数。
四、使用Wordpress插件实现Google+的更新:
1、Google Plus –这个插件使用简单,不需要Google+API,只需添加你的Google+ID即可实现。
2、Google Plus Widget – 这个插件不仅显示你的最新更新,还可显示你的个人头像和+1按钮、粉丝数等等。