9.3. Publishing Your Feed

Now that you have a functional RSS feed for your blog, you need to make it available to your users, so they can take advantage of your syndicated content.

9.3.1. Adding the Feed to the Blog

To make your feed available to users, add it to your blog by including it within index.php. You can do this in either of two ways (I'll show you how to use both approaches). First, you can add a <link> tag in the head of your HTML. Alternatively, you can place a direct link to the feed within the body of your document.

9.3.1.1. Using the <link> Tag to Signify an RSS Feed

Most modern browsers have RSS readers built in, so they recognize when a site has an available RSS feed. To make your feed recognizable, you need to add a <link> tag to the head section of index.php.

You've already used the <link> tag in this project to include an external CSS style sheet. To include the RSS feed, you use a similar process to you provide attributes that describe the document's title, location, type, and relationship of the feed. The relationship you provide is called alternate because the feed is an alternative method to view your content.

To mark this link as a feed, you set its type to application/rss+xml, which is the accepted content type for RSS feeds. The title and href attributes identify your feed.

To insert your feed, add the code in bold to the head section of index.php:

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <meta http-equiv="Content-Type"
        content="text/html;charset=utf-8" />
    <link rel="stylesheet"
        href="/simple_blog/css/default.css" type="text/css" />
    <link rel="alternate" type="application/rss+xml"
        title="My Simple Blog - RSS 2.0"
        href="/simple_blog/feeds/rss.php" />
    <title> Simple Blog </title>
</head>

Once you add your feed, you can load http://localhost/simple_blog/ and see a new RSS icon in the address bar of some browsers (see Figure 9-4).

Figure 9.4. An RSS icon (circled in red) appears in the address bar after you include a link to your feed

9.3.1.2. Adding an RSS Link

Next, you need to provide a direct link to the feed for users who have a feed reader other than a browser. This is as simple as adding an anchor element to the bottom of the page, just before the closing </div> and </body> tags.

Add the lines in bold to the bottom of index.php to link to your feed:

<p class="backlink">
        <?php if($page=='blog'): ?>
            <a href="/simple_blog/admin/<?php echo $page ?>">
                Post a New Entry
            </a>
        <?php endif; ?>
        </p>

<p>
            <a href="/simple_blog/feeds/rss.php">
                Subscribe via RSS!
            </a>
        </p>

    </div>

</body>

</html>

This link enables users to point their feed readers at your feed. When you reload http://localhost/simple_blog/ in your browser, you see the new link at the bottom of the blog entry previews (see Figure 9-5).

Figure 9.5. A link to your feed is added to the bottom of the page

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.237.123