Tìm Hiểu về Wordpress - part 22 potx

10 259 0
Tìm Hiểu về Wordpress - part 22 potx

Đang tải... (xem toàn văn)

Thông tin tài liệu

197 6.5.1 Tracking and Displaying Feed Statistics Once you get your feed established and properly configured, you will want to begin offering it to your visitors. There are many ways to do this, including text links, image links, and even FeedBurner badges that display the total number of subscribers for your feed. Along with the number of subscribers for your site, the free FeedBurner service also keeps track of many other types of statistical data. From subscriber count and click-throughs to user reach and page hits, FeedBurner is your one-stop resource for in-depth feed analysis. 6.5.2 Types of Statistics Provided by FeedBurner As discussed above, FeedBurner provides some great tools for managing, optimizing, and tracking your feeds. Here are some of the statistics provided by FeedBurner: • Subscribers counts – daily totals and chronological history • Feed reader applications that are used to access your feed • Uncommon uses, including re-syndication • Reach – the unique number of people who view or click your feed content • Item views – tracking of access to specied feed items • Item link clicks optimized for complete item use or search engine ranking • Item enclosure downloads, including podcast downloads As you can see, FeedBurner tracks just about everything you may need to know about your feed. Many of these statistics are included automatically with your account, but others are “opt-in” and require you to activate them. Fortunately, FeedBurner makes managing, using, and exporting your feed stats as pain-free 198 as possible, with everything fully accessible and configurable from within your account’s Admin area. 6.5.3 Displaying FeedBurner Statistics By far, one of the most popular uses of FeedBurner statistics is the public display of a feed’s subscriber count. There are many ways to display your subscriber count, including those little rectangular badges frequently seen in the sidebars of blogs and sites around the Web. These free “chicklets,” as they’re called, are delivered by FeedBurner and configurable via the FeedBurner Admin area. Depending on your site’s design, however, you may prefer to display your subscriber count in a way that better suits your specific design. Fortunately, there are alternate, “text-only” ways of displaying your subscriber count, thereby enabling you to display the number with the appropriate (X)HTML and CSS. Here are two methods of displaying your subscriber count in plain text, enabling you to markup and style the information in any way you wish and integrate it easily into your design. Method 1: Use PHP to display FeedBurner subscriber count Using FeedBurner’s Awareness API and a bit of PHP, it is possible to display your FeedBurner subscriber count as plain text. Here’s how to do it in three easy steps: 1. Open your sidebar.php theme file and add the following code to the location where you would like to show off your subscriber count: <?php $feed = "https://feedburner.google.com/api/awareness/1.0/ GetFeedData?uri=digwp"; $curl = curl_init(); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); FeedBurner Chicklets You can choose animated and non-animated chicklets, as well as customize the colors used. 199 curl_setopt($curl, CURLOPT_URL, $feed); $feed = curl_exec($curl); curl_close($curl); $xml = new SimpleXMLElement($feed); $feedburner = $xml->feed->entry['circulation']; echo $feedburner; ?> 2. Replace the term “digwp” in the first line with the username of your FeedBurner account. 3. Done! Markup and style the plain-text subscriber-count output as desired and enjoy the results. Method 2: Use a plugin! If you would rather just jump in and use a plugin to display your FeedBurner stats, Francesco Mapelli’s excellent Feed Count plugin (see side note) does the job very well. The plugin is a snap and provides all the functionality needed for customized text-display of your subscriber count. With the plugin’s text output of your feed stats, it is possible to echo virtually any message or markup you wish to embellish your data. 6.5.4 Alternatives to FeedBurner During the writing of this book, all FeedBurner accounts were transferred to Google. During this process, an enormous percentage of FeedBurner users experienced a sudden, drastic decrease in the number of reported subscribers. This was very upsetting to say the least, and led many people to begin exploring alternatives to the now-questionable FeedBurner service. “Are there any alternatives to FeedBurner?” We encounter this question Feed Count Plugin Unfortunately, at the time of this writing, the Feed Count web page was marked as an “attack site.” So, until the author resolves the issue, we have made the plugin available through our site at this URL: http://digwp.com/u/378 To the Streets! The FeedBurner problems made a lot of folks angry and was documented by TechCrunch here: http://digwp.com/u/90 200 As awesome as it is, the Feed Count plugin can’t work when the FeedBurner data is unavailable. Despite its best intentions, FeedBurner occasionally returns inaccurate data for the subscriber count. For those of us who care about the accuracy of our publicly displayed feed statistics, displaying information like this on your site is simply unacceptable: Join N/A awesome subscribers! …or perhaps even worse: Join 0 awesome subscribers! Ugh. Clearly not the way to leave a good impression and encourage visitors to subscribe to your feed. Fortunately, we have an excellent fallback mechanism to ensure that all visitors see the correct subscriber information. Begin by placing the following script in your active theme’s functions.php file: <?php function feedcount_fallback() { if(function_exists('fc_feedcount')) { ob_start(); fc_feedcount(); $count = ob_get_contents(); ob_end_clean(); if($count == 'N/A' || $count == '0') { echo 'many other'; } else { echo $count; } } else { echo 'many other'; } } ?> Once that code is in place, replace the default Feed Count function call with this in your theme’s template file: <p>Join <?php if (function_exists('feedcount_fallback')) feedcount_fallback(); ?> awesome subscribers!</p> Once in place, that code will output one of the following messages, depending on availability of accurate FeedBurner subscriber-count data: When the subscriber count is correct: “Join 243 awesome subscribers!” And when the subscriber count is either “N/A” or “0”: “Join many other awesome subscribers!” How does this script work? Basically, we are using PHP’s output buffering functionality to capture the output value of the fc_feedcount() function and compare it to the two possible error values (“N/A” and “0”). When the error values are detected, the alternate, fallback message is displayed; otherwise, the function displays the correct count value. Plus, as an added bonus, the function covers your bases by outputting the fallback message in the event that the Feed Count plugin itself should fail. This method ensures proper subscriber count display without relying on the availability of JavaScript, the accuracy of FeedBurner data, or even the functionality of the Feed Count plugin! More information at Perishable Press: http://digwp.com/u/89 Prevent FeedBurner Errors with a Fallback Mechanism 201 repeatedly every time FeedBurner drops the ball. Until recently, FeedBurner was pretty much it for delivering feeds and keeping track of statistics. This is one of the reasons why just about everybody is using FeedBurner – the competition has been scarce. Fortunately, some promising FeedBurner Alternatives are finally gaining some traction: • FeedBlitz http://digwp.com/u/91 FeedBlitz has been around as long as I can remember and should have been in the feed-delivery/tracking game from the beginning. Even so, better late than never with their new RSS delivery service. • RapidFeeds http://digwp.com/u/92 RapidFeeds publishes and monitors your RSS feeds for free. Looks relatively new but very promising. • FeedStats http://digwp.com/u/93 FeedStats is designed to track the total number of people who are subscribing to your various feeds. The total number of subscribers takes into account different feed formats, such as RDF, RSS, and Atom. • Feed Statistics http://digwp.com/u/94 In addition to tracking your daily subscriber count, the Feed Statistics plugin also monitors and reports information about which feed readers are being used to access your feeds, as well as data on Post Views, Top Feeds, and Click- throughs – all within the convenience of the WordPress Admin. 6.6.1 Customizing Feeds Once your feed is up and running, there are many ways to customize its appearance and functionality. If you are using FeedBurner, there are many different ways to style and present the feed to your visitors. Yet even without FeedBurner, there are many great ways to improve the appearance and functionality of your WordPress feeds. Let’s take a look at some popular and useful modifications. 202 It is a classic CSS sin to use inline styling. It completely defeats the purpose of using CSS, which is to separate content from design. If we wanted to call special attention to a box on the page, it would be smart for us to do something like: <div class="callout"> content </div> When we publish our content with RSS as WordPress does, people won’t be viewing our content on our website, but in whatever they use to read RSS content. This could literally be anywhere, but a classic example would be a reader reading through Google Reader. In the Google Reader environment, our special class of “callout” has no meaning whatsoever. On our own website, callout might mean it has some extra padding and a yellow background, but in Google Reader, it will have no effect at all. If we want to make that extra padding and yellow background come through over RSS, we can force it by using inline styling. <div style="padding: 15px; background: #fff3c4; margin: 0 0 10px 0;"> content </div> Just remember that inline styling is generally regarded as evil for a reason… if you ever needed to change the styling, you’d have to go back into every single Post that used it, instead of being able to just change the CSS for “callout.” Inline Stylin’ for RSS Inline styling in the Post Result in RSS reader 203 6.6.2 Formatting Feed Images Images, as in <img src" " alt=" " /> elements, are by default “inline” elements. That means despite them having a width and a height, they don’t break lines and kind of just go with the flow of the text around it. In your theme, the CSS might be taking charge and changing this default inline behavior. It is possible that images are set to block level elements in your stylesheet, which forces line breaks before and after them. Or the images could have special classes applied to them which float them left or right so text wraps around them. But unfortunately, your CSS doesn’t mean anything when the Post is being read through an RSS reader. Those images will revert to their old inline-level selves. One classic way of avoiding this problem is making sure you have an extra line break above and below the image tag when creating/ editing your Post. Here is a screenshot demonstrating this technique: The nicely oated image in this TechCrunch article reverts to a non-oated inline image in the RSS feed and is rather awkward. The empty lines above will ensure that the top paragraph, image, and bottom paragraph will all be automatically wrapped in <p> tags without implicitly using them. 204 One of the (slightly weird and confusing) things that WordPress does is automatically apply <br /> tags into posts where a single return was used, and automatically apply wrapping <p></p> tags to blocks of content separated by double line-breaks. The end result is that this image tag separated from other content by double line- breaks on either side will now be wrapped in paragraph tags, which are by default block-level elements. This effectively makes your image a block level element, and will prevent any weird text wrapping. Another option is to use inline styling on the images, for example: <img src=" " alt=" " style="oat: left; margin: 0 10px 2px 0;" /> This will be effective on the site and through the RSS feed, with the major shortcoming that should you ever need to update this styling you’ll have to return to this post and manually alter it (rather than a sweepingly simple CSS change). 6.6.3 Adding a Custom Feed Image Out of the box, WordPress feeds are very plain. Apart from any images that your posts or comments may include, your WordPress feeds appear without any logos or branding images. A great way to enhance your site’s brand is to add a custom image to your feeds. Here’s how to do it: 1. Add the following code to your theme’s functions.php file: function mwp_feedImage() { echo "<image> <title>Digging into WordPress</title> <url>http://digwp.com/images/feed-icon.png</url> <link>http://digwp.com/</link> <width>150</width> 205 <height>150</height> <description>Digging into WordPress</description> </image>"; } add_action('rss2_head', 'mwp_feedImage'); 2. Edit each of the different XML elements to reflect your site’s information. 3. That’s it! Save, upload and check out your new custom-branded RSS feed! Add custom image to Atom feed For Atom feeds, the process is very similar: 1. Add this code to your functions.php: function mwp_atomImage() { echo " <icon>http://digwp.com/images/favicon.ico</icon> <logo>http://digwp.com/images/feed-icon.png</logo> "; } add_action('rss2_head', 'mwp_atomImage'); 2. Edit each of the different XML elements to reflect your site’s information. 3. All done! Save, upload, and check out your new custom-branded Atom feed! Alternately, FeedBurner users may add a feed image to any of their feeds by using the “Feed Image Burner” feature available in their account admin area. Branding is Key Presenting a strong brand identity is a key part of your site’s success. Customizing your feeds with your logo is an excellent branding opportunity. 206 6.6.4 Include Comments in Feeds While WordPress excludes post comments from feeds by default, certain sites may benefit from including them. The easiest way to do so is to mashup a quick feed pipe at the free Yahoo! Pipes service http://digwp.com/u/169. Sounds complicated, but it’s really simple. Here’s how to do it in ten easy steps: 1. Sign into Yahoo! Pipes with your Yahoo! ID. 2. From the “Sources” menu in the left sidebar, drag an instance of the “Fetch Feed” badge to the working area. Merging Feeds As seen in this section, Yahoo! Pipes is an excellent way to merge multiple feeds into a single feed, but it’s not the only mashup service that does so. Another good service is RSS Mix, which you can check out at http://digwp.com/u/172 . types of statistical data. From subscriber count and click-throughs to user reach and page hits, FeedBurner is your one-stop resource for in-depth feed analysis. 6.5.2 Types of Statistics Provided. double line-breaks. The end result is that this image tag separated from other content by double line- breaks on either side will now be wrapped in paragraph tags, which are by default block-level. change). 6.6.3 Adding a Custom Feed Image Out of the box, WordPress feeds are very plain. Apart from any images that your posts or comments may include, your WordPress feeds appear without any logos or

Ngày đăng: 04/07/2014, 21:20

Tài liệu cùng người dùng

Tài liệu liên quan