1. Trang chủ
  2. » Công Nghệ Thông Tin

Tìm Hiểu về Wordpress - part 24 pdf

10 293 0
Tài liệu đã được kiểm tra trùng lặp

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

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 1,48 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

add_filter'the_excerpt_rss', 'insertContent';add_filter'the_content_rss', 'insertContent'; And, as you can imagine, we can follow this line of thinking to include custom content both bef

Trang 1

add_filter('the_excerpt_rss', 'insertContent');

add_filter('the_content_rss', 'insertContent');

And, as you can imagine, we can follow this line of thinking to include custom

content both before and after your feed post content:

function insertContent($content) {

$content = '

<p>This content appears before the feed post.</p>' $content '

<p>This content appears after the feed post.</p>';

return $content;

} add_filter('the_excerpt_rss', 'insertContent');

add_filter('the_content_rss', 'insertContent');

Awesome Plugins for Custom Feed Content

Looking for a great way to spice up your blog feeds? Here are some of the best “feed-footer” plugins available for enhancing your feeds with custom content, links, and much more!

• Better Feed WordPress Plugin http://digwp.com/u/174

A great plugin by the venerable Ozh that enables flexible customization of your feed footer Add a copyright notice, custom markup, “read-more” links, number of responses, related posts, and much more We use this plugin at the Digging into WordPress companion site http://digwp.com/ to help promote the book Highly recommended.

• RSS Footerhttp://digwp.com/u/175

This very simple plugin from WordPress guru Joost de Valk enables you to add an extra line of content to articles in your feed, defaulting to “Post from: ” and then a link back to your blog, with your blog’s name as its anchor text, which you can edit from the plugin’s Admin Options page.

• Authenticate http://digwp.com/u/176

Authenticate is a highly flexible content-addition plugin that enables universal and/or targeted inclusion of custom content for both feeds and posts Ideal for adding copyright information, distribution policy, thank-you messages, custom links, special offers, and much more Custom content may be added to any location within posts or feeds – before, after, or even within post content

Trang 2

6.6.11 Importing and Displaying External Feeds This idea takes the blogroll one step further Feed technology makes it easy to import and display virtually any feed on the Web anywhere on your site For example, you may want to upgrade that tired old blogroll with a sidebar section full of your friends’ recent posts Here are some plugins designed to help you import RSS feeds and display them on your site

• Parteibuch Aggregator http://digwp.com/u/177

Displays aggregated feeds in WordPress pages and sidebars Share the feeds you read with the visitors of your blog It is designed to be able to cope with hundreds of feeds, thousands of aggregated feed items and a lot of traffic

• InlineRSS WordPress Plugin http://digwp.com/u/178

Enables the importation and display of virtually any RSS feed This plugin will also display the titles of multimedia content and provide links to it

• FeedWordPress http://digwp.com/u/179

A completely customizable feed-import plugin that works with your blogroll to import and display your favorite feeds

• Khanh’s Quick Feeds WordPress Plugin http://digwp.com/u/180

Easily display feed content to your posts, pages, sidebar and virtually anywhere you can imagine This plugin includes a polling feature to ensure feed freshness

To display external feeds without using a plugin, we can use WordPress’ built-in RSS import functionality to get the job done Simply paste the following code anywhere in your theme (e.g., the sidebar or footer) where you would like the feed

to appear (edit according to the code comments):

<h2><?php _e('Imported External Feed'); ?></h2>

<?php include_once(ABSPATH WPINC '/feed.php');

// edit this line with the URL of the imported feed

$rss = fetch_feed('http://feeds2.feedburner.com/DiggingIntoWordpress'); // edit this line to specify the number of feed items

$maxitems = $rss->get_item_quantity(7);

Trang 3

$rss_items = $rss->get_items(0, $maxitems);

?>

<ul>

<?php if ($maxitems == 0) echo "<li>No items.</li>";

else

foreach ($rss_items as $item) : ?>

<li>

<a href="<?php echo $item->get_permalink(); ?>"

title="<?php echo $item->get_date('j F Y | g:i a'); ?>">

<?php echo $item->get_title(); ?></a>

</li>

<?php endforeach; ?>

</ul>

By including the feed.php file in the second line, we gain local access to the

fetch_feed() function, which enables us to easily import and display any feed we

wish We need only to edit the feed URL in the fourth line, and then specify the

number of feed items to display in the sixth line (the “7” in our example), and we

are all set

6.6.12 Buffer Period After Posting

Thanks to a tip from WPengineer http://digwp.com/u/181, we now enjoy a nice way to

provide a little time buffer between the moment of posting and the moment the

content appears in our feeds Before learning about this method, there was no way

to prevent mistakes from immediately appearing in feeds that were noticed after

hitting the “Publish” button Once the mistake is in the feed, it is beamed out all

over the place, leaving readers confused and you looking like a heel

Fortunately, we can avoid this embarrassing problem by placing the following code

into our theme’s functions.php file:

Trang 4

function publish_later_on_feed($where) { global $wpdb;

if (is_feed()) {

// timestamp in WP-format

$now = gmdate('Y-m-d H:i:s');

// value for wait; + device

$wait = '5'; // integer

$device = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

$where = " AND TIMESTAMPDIFF($device, $wpdb->posts.post_date_gmt, '$now') > $wait ";

} return $where;

} add_filter('posts_where', 'publish_later_on_feed');

As is, this code will provide a 5-minute buffer period for you to catch any errors and make any last-minute changes Five minutes later, your feed will be generated

as normal

This function takes advantage of the $where variable by comparing the query value

to the SQL function timestampdiff() After the specified time interval has elapsed, the post will be published to your feed Note that this function does not affect normal post publishing on your site Edit the $wait variable in the function to specify a different period of time

6.6.13 Protecting Feed Content The flexibility and mobility of feeds also makes them prone to abuse When normal visitors and subscribers get ahold of your feed, they usually add it to their feed reader of choice and enjoy the convenience of automatically updated, localized, and consolidated content

Trang 5

Conversely, when unscrupulous criminals get ahold of your feeds, they are free

to steal and abuse them As mentioned earlier, so-called “scraper” sites steal

feeds and display them on automated blogs in order to make money from

advertisements Yes, it sucks, but there are several things you can do to prevent this

type of frustrating behavior Let’s take a look…

Feed Footer Plugins

A great way to deter scrapers while customizing the functionality of your feeds

is to use one of the various “feed-footer” plugins In general, these plugins work

automatically in the background to add specific information to your feed posts

Many types of custom information may be added, including copyright statements,

digital fingerprints, post links, author information, and much more Here are a few

examples to consider:

• Better Feed WordPress Plugin http://digwp.com/u/174

Ozh’s Better Feed plugin enables you to customize your feeds with copyright info,

“Read-More” links, comment counts, related posts, Technorati links, and tons more

• Owen Winkler’s AntiLeech WordPress Plugin http://digwp.com/u/182

Deters and protects against content thieves by including a small “AntiLeech”

graphic in your feed’s output The graphic transmits user-agent data back to your

site for easy blocking Very comprehensive feed protection with tons of features

• Digital Fingerprint Plugin http://digwp.com/u/183

Places a digital fingerprint, customized and tailored by each individual user of this

plugin, into blog posts Once embedded in your post, the plugin allows you to

quickly and easily search the blogosphere for references to the digital fingerprint

• Angsuman’s Feed Copyrighter Plugin http://digwp.com/u/184

Adds a simple, unobtrusive copyright message to your feed items, thereby acting as

a deterrent to unscrupulous content thieves Quick, easy, and effective

Enable Partial Feeds

Perhaps the best way to prevent content theft is to enable the partial feed format

As discussed earlier in this chapter, enabling partial feeds discourages scrapers and

Trang 6

other thieves by rendering your feeds useless to automated processing Populating their scraper pages with partial posts is not as lucrative as it is with full posts Sure, some of your legitimate users may complain a little, but this is a great way to defend against stolen content

Link Back to Your Site Another effective method of preventing stolen content is to include links back to your site within your posts Many bloggers do this automatically as they write their content because it helps readers discover related content, and also facilitates the distribution of valuable link equity into other areas of your site

Best of all, when scraper sites display your intact feeds on their sites, all of those links that you have added to your content will be pointing right back at your site This acts as a strong signal to both visitors and search engines concerning the original source of the material

6.7.1 Validating Feeds

In this chapter, we have learned lots of essential information concerning WordPress feeds Now that we know what they are, where they are, and how to customize our feeds, let’s wrap things up by looking at an important practice when delivering

syndicated content to your readers: validating your feeds.

With so many different feed readers available to choose from, it is vital to ensure that your feeds are being generated and delivered as intended The last thing you want is to spend your time and effort writing content that is not being displayed properly because of errors Fortunately, there are plenty of free online Feed Validators that will help you check your feeds for accuracy Let’s have a look

Free online feed validators

In the process of configuring your WordPress feeds, it is a good idea to check your feeds for proper validation with any of the available online feed validation

Take Advantage

It never ceases to amaze us to

see how many thieves scrape

the content of popular sites like

Smashing Magazine, Noupe,

NetTuts, and the like If one

of your posts is fortunate

enough to get a link in a post

from one of these sites, don’t

be surprised to see gazillions

of pingbacks back to your site

Sure, the linkbacks are coming

from scraper sites, but it’s still

a good reason to include plenty

of internal links in your posts.

Trang 7

services Here a few to choose from:

• http://feedvalidator.org/

• http://validator.w3.org/feed/

• http://www.atomenabled.org/feedvalidator/

And of course, there are many other good

validators as well To validate your feed,

visit one of these sites and enter the URL of the feed you would like to check If all

goes well, you should see something like the image to the right

6.7.2 Diagnosing and Troubleshooting Errors

Of course, things don’t always go according to plan While WordPress has gotten

better at generating valid feeds, there are many potential points of failure,

including in-post markup, scripts, and even certain types of text content that may

cause your feeds to validate as less than perfect A much more common scenario

these days is to validate a feed that elicits only “recommendations” from the

validator

If this happens, you may want to look into the various recommendations and see

if anything is easily fixed Throughout the course of WordPress’ development, the

validity of its feeds has waxed and waned according to changes in both WordPress

and the algorithms of the feed validators

For each error or recommendation listed in the validation results, the validator will

list a key phrase (usually highlighted in yellow) along with a “help” link When

attempting to diagnose, troubleshoot, and repair these warnings, use the key

phrase to search the Web for more information Include the exact phrase in quotes,

and also include any other associated terms, such as “WordPress,” “posts feed,”

“line number ##,” and anything else that may help refine the search results

Trang 8

Of course, those “help” links are also generally useful and should be investigated

as well Often times, the issue is something very common and easy to resolve

If all else fails, and you are unable to pinpoint and correct the cause of the error

or warning, you can always install a clean version of WordPress, test the feed, and then re-build your site from the ground up During this process, as you sequentially install your plugins and make other modifications, remember to test the feed after each change to your site This process can be tedious, but is generally a reliable way

of determining the cause of the issue

Moving on…

In this chapter, we have learned a great deal about setting up, using, and customizing WordPress feeds In the next chapter, we explore the exciting world of WordPress comments and dig into different ways of customizing, enhancing and improving the functionality of your WordPress comment system

Trang 9

Nick La’s Web Designer Wall

features an artistic design

that has inspired many sites

around the Web Built with

WordPress, WDW shares

design-related articles covering

everything from Photoshop and

Flash tutorials to SEO tips

and web-design trends.

www.webdesignerwall.com

Trang 10

Think like a wise man but communicate

in the language of the people.

– W I L L I A M B U T L E R Y E A T S

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

TỪ KHÓA LIÊN QUAN

w