Tìm Hiểu về Wordpress - part 23 docx

10 280 0
Tìm Hiểu về Wordpress - part 23 docx

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

Thông tin tài liệu

207 3. Add your Post Feed and Comments Feed to the “Fetch Feed” badge. Click the plus “+” sign to get another input field. 4. From the “Operators” menu in the left sidebar, drag an instance of the “Sort” badge to the working area. 5. In the “Sort” badge, select the “item.pubDate” option and sort in descending order. 6. You should have three badges at this point: “Fetch Feed,” “Sort,” and “Pipe Output,” which was added to the working area automatically. 7. Connect the three badges by connecting the circles on the upper and lower edges (see screenshot on previous page). 8. Click the “Refresh” button in the debugger window below the working area to see the output of the piped feed. 9. To save your feed, click “Save” in the top-right area of the screen and name your new pipe. After saving is complete, click “Run Pipe” at the top of the screen. A new window will then open with configuration options and so forth. 10. Once everything is properly configured, click “Publish” to make it official. The URL of your RSS-formatted feed is available by clicking the “Get as RSS” link next to the feed icon. That’s all there is to it! You now have a shiny new feed that contains your posts and comments in chronological order. Of course, there is much more you can do with the incredibly awesome Yahoo! Pipes service, so feel free to experiment and have some fun. By the way, you can check out the DiW Posts and Comments feed used for this tutorial at http://digwp.com/u/170. 208 6.6.5 Creating Custom Feeds There are many situations in which the default WordPress feeds simply won’t do. For example, you may have a category or group of categories that you would like to exclude or include in your main site feed. Fortunately, WordPress provides plenty of special feed parameters that enable you to carefully craft the perfect custom feed. Exclude categories, authors, and more from feeds Here is the general format for excluding content such as specific categories, authors and so on: http://digwp.com/feed?cat=-n Here we need to change “n” to the category ID for which we want to exclude. After doing so, our RSS feed will include all content except for that from the specified category. Likewise, we can exclude multiple categories like so: http://digwp.com/feed?cat=-x,-y,-z Here we would replace “x”, “y”, and “z” with the three categories of our choice. Similarly, additional categories may be added by simply adding an additional “,-n” to the end of the query string. Likewise, we may exclude specific authors, dates, and much more by simply replacing the “cat” parameter and its corresponding value(s) with any of the following parameters: • author=-n - excludes all posts posted from the Author with ID of “n” • year=-2009 - excludes all posts published in the specified four-digit year • monthnum=-11 - excludes all posts published in the specified month number • day=-22 - excludes all posts published on the specified day Subscribe to Your Own! During the process of setting up a new feed, it is always a good idea to grab a subscription for yourself. Adding your feed to a few different feed readers is a great way to keep an eye on your feed and ensure that it is looking good. 209 • paged=-33 - excludes all posts contained on the specified archive page • s=-wordpress - excludes all posts containing the search term “wordpress” • category_name=-wordpress - excludes all posts in the “wordpress” category You can also consolidate date-based custom-feed restrictions using the special “m” parameter: http://digwp.com/feed?m=2009 - excludes content from 2009 http://digwp.com/feed?m=200907 - excludes content from July, 2009 http://digwp.com/feed?m=20090707 - excludes content from July 7th, 2009 You may also combine these parameters to generate custom-fit WordPress feeds. Here are some examples: http://digwp.com/feed?cat=-11&s=-apple This would generate a feed that excludes category #11 as well as any posts containing the term “apple.” http://digwp.com/feed?cat=-11&year=-2008&author=-3 This would generate a feed that excludes category #11, excludes posts from 2008, and excludes posts written by author #3. As you can see, the pattern is simple: /feed?parameter01=value01&parameter02=value02&parameter03=value03 As you can see, each parameter-value pair is concatenated via the “&” symbol. If modifying your feed URLs is not your preferred way of excluding categories from feeds, you may want to check out the Ultimate Category Excluder plugin from Michael Clark http://digwp.com/u/171. 210 Excluding categories via functions.php Apart from URL-modification or using a plugin, it is also possible to exclude categories and other parameters from your feeds by placing the following script in your theme’s functions.php file: // exclude categories from feed function excludeCatsfromFeed($query) { if ($query->is_feed) { $query->set('cat','-x,-y,-z'); // excluded categories } return $query; } add_lter('pre_get_posts','excludeCatsfromFeed'); Once in place, go ahead and edit the “x”, “y”, and “z” to match the IDs of the categories you wish to exclude. You may also add or remove categories, or even exclude other items by replacing the “cat” parameter in the third line with any of the available query parameters discussed previously. This function makes it easy to deliver customized feeds in an extremely flexible fashion. Once in place, any posts belonging to the specified categories will no longer be displayed. Custom feed including only specific categories, authors, etc. Including specific content in your feeds is as simple as removing the minus sign “-” from the various formats presented above. All of the same parameters and their corresponding values may be used. Here are some examples to clarify the technique: 211 Generate a feed containing content from only categories “x”, “y”, and “z” http://digwp.com/feed?cat=x+y+z Generate a feed including content strictly from category 11 that also includes the term “apple” http://digwp.com/feed?cat=11&s=apple Generate a feed including content only from category 11, the year 2008, and from author 3 http://digwp.com/feed?cat=11&year=2008&author=3 Generate a feed consisting of multiple tags http://digwp.com/?feed=rss&tag=tag1,tag2,tag3 …and so on. Many combinations of these parameters are possible, enabling you to configure the perfect feed for your readers. Including categories via functions.php For those of you not comfortable with the idea of messing around with your feed’s URL, it is also possible to include categories and other parameters in your feeds by placing the following script in your theme’s functions.php file: // include categories in feed function includedCatsFeed($query) { if ($query->is_feed) { 212 $query->set('cat','x,y,z'); // included categories } return $query; } add_lter('pre_get_posts','includedCatsFeed'); Once in place, go ahead and edit the“x”, “y”, and “z” to match the IDs of the categories you wish to include. You may also add or remove categories, or even exclude other items by replacing the “cat” parameter in the third line with any of the available query parameters discussed previously. This function makes it easy to deliver customized feeds in an extremely flexible fashion. Once in place, only posts belonging to the specified categories will be displayed. 6.6.6 More Feed Customization Tricks Just in case all of those customization tricks weren’t enough, here are a few more that you may find helpful: Alphabetize feed posts in ascending order by title http://digwp.com/feed?orderby=title&order=asc Feed for a specific page http://digwp.com/page/feed Alternate format for specific page http://digwp.com/feed?pagename=page 213 Alternate format for specific page http://digwp.com/feed?page_id=n 6.6.7 Styling Feeds Although certain “purists” will tell you to never style your feeds, many people choose to do so to improve upon the ultra-plain default style that most feed readers provide. By adding a few custom CSS styles to your feeds, it is possible to improve your site’s image, increase brand awareness, and facilitate usability. The easiest way to add some CSS pizazz to your feed is to add inline styles via the impressive Feedstyler plugin. The Feedstyler plugin is perfect for WordPress users who are comfortable with CSS and wish to add custom styles to their WordPress feeds. Feedstyler retains class and ID attributes in your markup while enabling you to specify alternate feed styles. In addition to keeping your site and feed styles separate, Feedstyler also accepts nested CSS declarations, accepts multiple class names, and works on all feed readers that do not remove inline styles from the XML markup. The plugin has certain limitations in terms of what it can and can not do, but overall it’s a great way to style your feeds. Check it out at http://digwp.com/u/173. 6.6.8 Removing the WordPress Version Number By default, WordPress provides your WordPress version in your feeds. If you peek under the hood and look at the source code for any of your WordPress feeds, near the top of the file, you will see that WordPress includes its version number declared via <generator> elements: <generator>http://wordpress.org/?v=2.7</generator> While this is useful information to legitimate sources, it serves as a slight security risk by enabling attackers to target any specific security holes that may be present 214 in your particular version of WordPress. Thus, it is a good idea to remove this information from your feeds and your theme’s header file as well. To remove this information from your site’s feeds, include the following function in your theme’s functions.php file: function killVersion() { return ''; } add_lter('the_generator','killVersion'); This will replace your WordPress version with literally nothing whenever its generating function is called. To also remove the version information in the header, we take a slightly different approach with this line in the functions.php file: <?php remove_action('wp_head', 'wp_generator'); ?> This simple yet effective code prevents the wp_generator function from appearing in your theme’s header.php file. Clean Up Your Head In addition to using remove_action('wp_head','wp_generator') to remove the version info, you may also remove the annoying RSD (Really Simple Discovery) link by using remove_action('wp_head','rsd_link'). Likewise, to remove the WLW (Windows Live Writer) code, use remove_action('wp_head','wlwmanifest_link'). In fact, you can remove any of the content that is automatically displayed in your WordPress <head> section by applying any of the following to your theme’s functions.php file: <?php remove_action('wp_head', 'rsd_link'); // kill the RSD link ?> <?php remove_action('wp_head', 'wlwmanifest_link'); // kill the WLW link ?> <?php remove_action('wp_head', 'index_rel_link'); // kill the index link ?> <?php remove_action('wp_head', 'parent_post_rel_link', 10, 0); // kill the prev link ?> <?php remove_action('wp_head', 'start_post_rel_link', 10, 0); // kill the start link ?> <?php remove_action('wp_head', 'feed_links', 2); // kill post and comment feeds ?> <?php remove_action('wp_head', 'feed_links_extra', 3); // kill category, author, and other extra feeds ?> <?php remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // kill adjacent post links ?> <?php remove_action('wp_head', 'wp_generator'); // kill the wordpress version number ?> 215 6.6.9 Disable and Redirect Unwanted Feed Formats As previously discussed, WordPress generates your various feeds in a variety of formats, including RDF, RSS 2.0, and Atom. This is great while you are configuring your feeds for optimal distribution, however, if and when you settle on a specific format (such as RSS 2.0), you may want to disable and redirect those alternate feed formats for the sake of clarity, uniformity, and statistical analysis. Using the following code in your theme’s functions.php file, any requests for the specified feeds will be redirected to the URL of your choice. Place this into your functions.php file: // redirect feed function redirectFeed() { wp_die(); header("Location: http://digwp.com/feed/"); exit(); } Edit the URL in the third line with something useful, like your home page, a “Subscribe” page, or even your active Posts Feed. Once this is done, specify which alternate feed formats should be redirected by including any of the following lines directly beneath the previous function: add_action('do_feed', 'redirectFeed', 1); // all feeds add_action('do_feed_rdf', 'redirectFeed', 1); // RDF (RSS 0.92) feed add_action('do_feed_rss', 'redirectFeed', 1); // RSS 1.0 feed add_action('do_feed_rss2', 'redirectFeed', 1); // RSS 2.0 feed add_action('do_feed_atom', 'redirectFeed', 1); // Atom feed 216 6.6.10 Insert Custom Content into Feeds One of the easiest things that you can do with WordPress is add custom content to your posts. The custom content can be anything – text, markup, or even scripts – and may be set to appear in blog posts, feed posts, or both. You can easily set content to display before or after your post content, or in both places, if desired. Good examples of how this sort of functionality is used include the addition of copyright notices displayed in the feed footer, and advertisements appearing before and/or after each feed item. The possibilities are endless. To add some custom content to your own feed, place the following code snippet to your active theme’s functions.php file: function insertContent($content) { $content = $content . '<p>Place your custom content here!</p>'; return $content; } add_lter('the_excerpt_rss', 'insertContent'); add_lter('the_content_rss', 'insertContent'); Simply edit the second line of the function to include the desired code, markup, or text content. This function works by appending the specified custom content to the post content. Then, to ensure that the added content is only included within your feeds, we are using WordPress’ add_lter() function to execute the code only for full and excerpted feed content. Further, by slightly tweaking the code, you can insert custom content to appear before your regular feed content: function insertContent($content) { $content = '<p>Place your custom content here!</p>' . $content; return $content; } Easy Ad Inserts Using the code in this section, inserting advertisements into your feeds is a snap. . good. 209 • paged =-3 3 - excludes all posts contained on the specified archive page • s= -wordpress - excludes all posts containing the search term wordpress • category_name= -wordpress - excludes all. parameters: • author=-n - excludes all posts posted from the Author with ID of “n” • year =-2 009 - excludes all posts published in the specified four-digit year • monthnum =-1 1 - excludes all posts. examples: http://digwp.com/feed?cat =-1 1&s=-apple This would generate a feed that excludes category #11 as well as any posts containing the term “apple.” http://digwp.com/feed?cat =-1 1&year =-2 008&author =-3 This

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