• Aucun résultat trouvé

Adding Social Bookmarking Support 1. Create a folder named social_icons in your seophp folder

Dans le document Search Engine Optimization with PHP (Page 190-198)

2.

Download the code archive of this book, and copy the social bookmarking images from the archive to your social_iconsfolder. (The welcome.htmldocument from the code download contains details about the exact locations of the necessary files.)

3.

Create a new file named social_bookmarking.inc.phpin your seophp/includefolder, and type this code in:

<?php

// +---+

// | SocialBookmarking | // | Displays links for various social bookmarking services | // +---+

// | Copyright (c) 2005 Jaimie Sirovich | // +---+

// | Author: Jaimie Sirovich <jsirovic@gmail.com> | // | Icons taken from WordPress Plugin Sociable by Peter Harkins | // | (http://push.cx) | // +---+

class SocialBookmarking {

var $_link;

var $_title;

var $_site_name;

var $_templates = array(

‘blinkbits’ => array(

‘icon’ => ‘blinkbits.tif’,

‘url’ => ‘http://www.blinkbits.com/bookmarklets/save.php?v=1&source_url=i

‘icon’ => ‘linkagogo.tif’,

‘icon’ => ‘yahoomyweb.tif’,

// returns the HTML with social bookmarking symbols function getHTML($sites =

array(‘del.icio.us’, ‘digg’, ‘Furl’, ‘Reddit’, ‘YahooMyWeb’)) {

// build the output

$html_feed = ‘<ul class=”social_bookmarking”>’;

// create HTML for each of the sites received as parameter foreach($sites as $s)

{

if ($_site_info = $this->_templates[$s]) {

$html_feed .= ‘<li class=”social_bookmarking”>’;

$url = str_replace(array(‘{LINK}‘, ‘{TITLE}‘, ‘{SITENAME}‘), array(urlencode($this->_link),

urlencode($this->_title), urlencode($this->_site_name)),

$_site_info[‘url’]);

$html_feed .= ‘<a rel=”nofollow” href=”‘ . $url . ‘“ title=”‘ . $s . ‘“>’;

$html_feed .= ‘<img src=”‘ . SITE_DOMAIN .

‘/social_icons/‘ . $_site_info[‘icon’] . ‘“ alt=”‘ . $s .

‘“ class=”social_bookmarking” />’;

// returns HTML with social bookmarking links for inclusion in feeds function getFeedHTML($sites =

urlencode($this->_title), urlencode($this->_site_name)),

$_site_info[‘url’]);

$html_feed .= ‘<a rel=”nofollow” href=”‘ . $url .

‘“ title=”‘ . $s . ‘“>’;

$html_feed .= ‘<img src=”/social_icons/‘ . $_site_info[‘icon’] .

‘“ alt=”‘ . $s . ‘“ class=”social_bookmarking” />’;

$html_feed .= ‘</a> ‘;

} }

// return the HTML feed

return ‘<p>’ . $html_feed . ‘</p>’;

} }

?>

4.

Modify seophp/catalog.phplike this:

<?php

// load the URL factory library

require_once ‘include/url_factory.inc.php’;

// load social bookmarking helper class

require_once ‘include/social_bookmarking.inc.php’;

?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN”

“http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>

// instantiate class by providing link, title, and site name

$social = new SocialBookmarking(‘http://seophp.example.com/catalog.html’,

<a href=”popup.php” target=”_blank”>Find more about Professional Search Engine Optimization with PHP!</a>

5.

Load http://seophp.example.com/catalog.html, and you should get the result you see in Figure 7-7.

6.

Now take a look at how to add the same functionality to feeds. The SocialBookmarkingclass has a method named getFeedHTML(), which can be used for that purpose. Essentially, getHTML and getFeedHTMLare very similar, but your output will be a bit different for feeds. In this case, getHTML()uses an unordered list to display the links, whereas getFeedHTML()simply sepa-rates the links using spaces. Modify the code in rss_factory.inc.phpto add social book-marking links at the end of each feed, like this:

<?php

// load social bookmarking helper class require_once ‘social_bookmarking.inc.php’;

// add a feed item and its contents echo ‘<item>’;

foreach ($feed_item as $item_name => $item_value) {

// add social bookmarking icons to feed description if ($item_name == ‘description’)

{

// instantiate class by providing link, title, and site name

$social = new SocialBookmarking($feed_item[‘link’],

$feed_item[‘title’],

$this->_title);

// add social bookmarking icons to the feed

$item_value = $item_value . $social->getFeedHTML();

7.

Load the feed at http://seophp.example.com/feed.phpagain in your browser, and notice the new social bookmarking links, as shown in Figure 7-8.

Figure 7-7

Figure 7-8

The newly created library knows how to generate links for many social networking web sites: blinkbits, blinklist, blogmarks, co.mments, connotea, del.icio.us, de.lirio.us, digg, Fark, feedmelinks, Furl, LinkaGoGo, Ma.gnolia, NewsVine, NetVouz, Reddit, scuttle, Shadows, Simply, Smarking, Spurl, TailRank, Wists, and YahooMyWeb. Wow, this is quite an impressive list, isn’t it?

Whenever you add something interesting that other people may want to talk about, you want to facili-tate them in doing so. After creating the SocialBookmarkingclass and referencing it from the page where your content is located, you simply need to use it like you did in catalog.php:

<center>

<?php

// instantiate class by providing link, title, and site name

$social = new SocialBookmarking(‘http://seophp.example.com/catalog.html’,

‘Exciting SEOEgghead Products!’,

‘SEOEgghead’);

// display social bookmarking links echo $social->getHTML();

?>

</center>

The HTML output, of course, can be customized. We won’t insist on such customization here though.

Also, note the getHTML()method has an optional array parameter that contains the services for which to create links. The default value is array(‘del.icio.us’, ‘digg’, ‘Furl’, ‘Reddit’,

‘YahooMyWeb’), but you can specify any of the known services if you don’t like the default list.

Summar y

Feeds provide a streamlined method for users to access content, as well as allow other sites to syndicate content. Links that are embedded in the feeds will both provide traffic directly as well as indirectly over time. Users will click the embedded links in the syndicated content. And search engines will see a grad-ually increasing number of links. This chapter demonstrated a class to easily create an RSS 2.0 feed, as well as a third-party class to read all of the various formats employed today.

Social bookmarking services offer another sort of organic traffic that should also not be ignored. Stream -lining the process of bookmarking on your web site will likely increase the number of bookmarks your site receives, and hence its ranking in the social bookmarking site search function — and perhaps even earn a place on its home page.

Dans le document Search Engine Optimization with PHP (Page 190-198)