<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>Oscar Dias - Personal Blog</title>
	
	<link>http://oscardias.com</link>
	<description>Software Development and Related Topics</description>
	<lastBuildDate>Thu, 17 May 2012 22:25:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/oscardias" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="oscardias" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">oscardias</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Creating a CodeIgniter App (Part 1): Introduction</title>
		<link>http://oscardias.com/development/php/codeigniter/creating-a-codeigniter-app-part-1-introduction/</link>
		<comments>http://oscardias.com/development/php/codeigniter/creating-a-codeigniter-app-part-1-introduction/#comments</comments>
		<pubDate>Mon, 14 May 2012 20:35:18 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Task Board]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=273</guid>
		<description><![CDATA[Last week I wrote about a small CodeIgniter app called Simple Task Board. It is capable of managing multiple projects and tasks, but it is very simple, specially now that it is in the first version. So I thought it would be a good idea to explain how it was done. This explanation will occur [...]]]></description>
			<content:encoded><![CDATA[<p><em><a title="PHP Project: Simple Task Board" href="http://oscardias.com/development/php/codeigniter/php-project-simple-task-board/">Last week</a> I wrote about a small CodeIgniter app called Simple Task Board. It is capable of managing multiple projects and tasks, but it is very simple, specially now that it is in the first version. So I thought it would be a good idea to explain how it was done. This explanation will occur in a series of posts, starting today with an introduction about CodeIgniter and about this specific application.</em></p>
<p><span id="more-273"></span></p>
<h1>Introduction</h1>
<p><a title="CodeIgniter" href="http://codeigniter.com/">CodeIgniter</a> is a MVC (model-view-controller) Framework for PHP with a small footprint. This means that it features a complete set of functions that helps you to organize and speed up the development process of web applications. Besides, it is quite simple when compared to some other frameworks.</p>
<p>The community around a framework is also something to take in consideration when choosing one. CodeIgniter has an active community and a good user guide, so it is easy to find the information you need. Now let me explain what MVC means.</p>
<h3>Model-View-Controller</h3>
<p>It is design pattern that divides the application in three parts:</p>
<ul>
<li>Model: database interaction and business logic. CRUD (create, read, update, delete) operations.</li>
<li>View: what the user sees. Our HTML.</li>
<li>Controller: application logic and user input handling. The controller uses the model to get/set the information in the database and calls the necessary views to display it to the user.</li>
</ul>
<p>Simply explained, it is an architecture or model to structure your application. For those who have already worked with pure PHP applications that handle inputs in the same file where the HTML is, includes the database connection and executes the database actions, working with a MVC framework is awesome. At first it might look difficult, but after a few moments understanding the simplicity and organization of the code, you won&#8217;t work without it again.</p>
<h1>Structure and Files</h1>
<p>The CodeIgniter installation has a standard folder structure. This can be changed by tweaking a few files, but for the purpose of this application we will keep the folder structure as it is. So go to <a title="CodeIgniter" href="http://www.codeigniter.com">http://www.codeigniter.com</a> and download the latest version (right now 2.1.0). Unzip the contents into your desired folder. This is what you&#8217;ll see:</p>
<ul class="directory">
<li class="directory">application</li>
<li class="directory">system</li>
<li class="directory">user_guide</li>
<li class="phpfile">index.php</li>
<li class="genericfile">license.txt</li>
</ul>
<p>The file <em>index.php<em> indicates the environment (development, production, etc) and the system and application folders. So, if you want, you can rename this folders for something else and change this value in the <em>index.php<em> file. This helps improving the security of your app.</em></em></em></em></p>
<p>The file <em>license.txt</em> contains the legal agreement for the use of CodeIgniter.</p>
<h3>application</h3>
<p>This is the folder where all information specific to our application will go. The most important subfolders, where you will doing most of your work, are:</p>
<ul class="directory">
<li class="directory">config: the app configuration. Database settings, autoload libraries and helpers, routes, etc.</li>
<li class="directory">controllers: app controllers. Each controller is a PHP class that extends the CI_Controller class. To access the controller you simply go to server/controller_name in your browser.</li>
<li class="directory">models: database models. The models are also classes, but they extend the CI_Model class.</li>
<li class="directory">views: all your views will be here.</li>
</ul>
<p>There are many other subfolders, like libraries and helpers, where you can add your custom classes and functions.</p>
<h3>system</h3>
<p>This folder contains the &#8220;engine&#8221; of CodeIgniter. All the system libraries are here, so you don&#8217;t need to worry about it.</p>
<h3>user_guide</h3>
<p>As you can imagine this is the user guide that comes with CodeIgniter. You can remove this folder or keep it in a separate place for reference. You can find this <a title="CodeIgniter User Guide" href="http://codeigniter.com/user_guide/">user guide online</a> as well.</p>
<h1>Simple App Flow</h1>
<p>This is a simplified flow to explain how a simple scenario works.</p>
<p style="text-align: center;"><a href="http://oscardias.com/wp-content/uploads/2012/05/CodeIgniter-Flow.png"><img class="size-medium wp-image-283 aligncenter" title="CodeIgniter Flow" src="http://oscardias.com/wp-content/uploads/2012/05/CodeIgniter-Flow-300x203.png" alt="" width="300" height="203" /></a></p>
<p>In this scenario we are accessing a user to edit his details. CodeIgniter handles URLs in a simple way, using the first part as the controllers and the next one as the method. Any other values can be parameters of the method. If the controller is not defined the default one will be loaded (this is defined in the config folder). If the method is not defined, the index method will be used by default.</p>
<p>I will explain in detail how we do everything in the next posts. My intention is to go step by step, explaining how CodeIgniter works in practical situations. Now let me explain what the application will be.</p>
<h1>Simple Task Board</h1>
<p>The application we will be creating is the Simple Task Board. It is available <a title="PHP Project: Simple Task Board" href="http://oscardias.com/development/php/codeigniter/php-project-simple-task-board/">here in this blog</a> as well as in <a title="GitHub Repository" href="https://github.com/oscardias/Simple-Task-Board">GitHub</a>. It was created by myself, to help me organizing my personal projects. I decided to make it available in order to improve it and, maybe, use it to help me manage projects in my company. As I don&#8217;t need and don&#8217;t want to loose to much time managing the projects, I don&#8217;t need many features. I end up using an agile board or simple spread sheets. That&#8217;s why the Simple Task Board could be tailored to support only the basic needs, being at the same time simple and useful.</p>
<h1>Conclusion</h1>
<p>That&#8217;s all for the introduction. I&#8217;ve prepared a new installation of CodeIgniter in my local machine, so I&#8217;m ready to start the step by step tutorial. Next weekend I&#8217;ll prepare part 2 of the tutorial. Have a nice week.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=feiE9If5CXg:DWwD3bvqnxw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=feiE9If5CXg:DWwD3bvqnxw:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=feiE9If5CXg:DWwD3bvqnxw:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=feiE9If5CXg:DWwD3bvqnxw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/development/php/codeigniter/creating-a-codeigniter-app-part-1-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Project: Simple Task Board</title>
		<link>http://oscardias.com/development/php/codeigniter/php-project-simple-task-board/</link>
		<comments>http://oscardias.com/development/php/codeigniter/php-project-simple-task-board/#comments</comments>
		<pubDate>Thu, 03 May 2012 16:29:20 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[GitHub]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Project Management]]></category>
		<category><![CDATA[Task Board]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=246</guid>
		<description><![CDATA[Simple Task Board is a very simple tasks management app. It is intended for people like me, that don&#8217;t need the power of one of these complex tools and/or don&#8217;t want to pay for them. Besides that, it is just another task management tool, built from scratch, open source, that anyone can help giving ideas [...]]]></description>
			<content:encoded><![CDATA[<p><em>Simple Task Board is a very simple tasks management app. It is intended for people like me, that don&#8217;t need the power of one of these complex tools and/or don&#8217;t want to pay for them. Besides that, it is just another task management tool, built from scratch, open source, that anyone can help giving ideas and playing with it. Maybe with the support of the community we can keep it simple, while addressing the most common issues. This post will act as a information repository about the app, working as a entry point for the <a title="Simple Task Board GitHub Repository" href="https://github.com/oscardias/Simple-Task-Board">GitHub repository</a>.</em></p>
<p><span id="more-246"></span></p>
<h1>Introduction</h1>
<p>Created using CodeIgniter, the idea is that this application will remain simple, supporting only the most basic requirements of a task management system. It&#8217;s goal is to aid in the project management process.</p>
<p class="simplenote">This is the first usable version of this application. Please use it only for testing and learning purposes.</p>
<p>The current version is 1.0. But it is under development and not fully tested. It should be used only for testing or if you want to learn a little bit more about CodeIgniter. In the next sections I&#8217;ll cover the following topics:</p>
<ul>
<li>Installation</li>
<li>Screen Shots</li>
<li>Future Updates</li>
<li>Download</li>
</ul>
<h2>Installation</h2>
<p>Create the database using db/create.sql, place the files in your server and update the following:</p>
<ul>
<li>application/config/config.php: update $config['base_url'] with your URL.</li>
<li>application/config/database.php: update your database information.</li>
</ul>
<p>Run &lt;server&gt;/install (where &lt;server&gt; should be your localhost or domain/folder).<br />
If you have any problems let me know.</p>
<h2>Screen Shots</h2>

<a href='http://oscardias.com/development/php/codeigniter/php-project-simple-task-board/attachment/task-board-edit-task-2/' title='Task Board   Edit Task  2'><img width="150" height="150" src="http://oscardias.com/wp-content/uploads/2012/05/Task-Board-Edit-Task-2-150x150.png" class="attachment-thumbnail" alt="Task Board   Edit Task  2" title="Task Board   Edit Task  2" /></a>
<a href='http://oscardias.com/development/php/codeigniter/php-project-simple-task-board/attachment/task-board-login/' title='Task Board   Login'><img width="150" height="150" src="http://oscardias.com/wp-content/uploads/2012/05/Task-Board-Login-150x150.png" class="attachment-thumbnail" alt="Task Board   Login" title="Task Board   Login" /></a>
<a href='http://oscardias.com/development/php/codeigniter/php-project-simple-task-board/attachment/task-board-project-test/' title='Task Board   Project  Test'><img width="150" height="150" src="http://oscardias.com/wp-content/uploads/2012/05/Task-Board-Project-Test-150x150.png" class="attachment-thumbnail" alt="Task Board   Project  Test" title="Task Board   Project  Test" /></a>
<a href='http://oscardias.com/development/php/codeigniter/php-project-simple-task-board/attachment/task-board-dashboard/' title='Task Board   Dashboard'><img width="150" height="150" src="http://oscardias.com/wp-content/uploads/2012/05/Task-Board-Dashboard-150x150.png" class="attachment-thumbnail" alt="Task Board   Dashboard" title="Task Board   Dashboard" /></a>

<h2>Future Updates</h2>
<p>I plan to update some portions of this application in the following months. Currently these are the features to be developed:</p>
<ul>
<li>Task comments: add comments in each task.</li>
<li>User levels: implement level verification to allow the correct functionalities to each level.</li>
<li>User profile: create a user profile with more information about the users.</li>
<li>Task history: track what happens with the tasks and how long it takes in each phase.</li>
<li>Tasks estimation: add an estimation field to enable a comparison between estimated and realized.</li>
<li>&#8230; if you have any ideas, let me know &#8230;</li>
</ul>
<h2>Download</h2>
<p class="downloadnote">If you want to download this project, please go to the <a title="Simple Task Board GitHub Repository" href="https://github.com/oscardias/Simple-Task-Board">GitHub repository</a>. This way you can download the latest version.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=F_Ji2ywyDcE:x65hBgWik5c:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=F_Ji2ywyDcE:x65hBgWik5c:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=F_Ji2ywyDcE:x65hBgWik5c:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=F_Ji2ywyDcE:x65hBgWik5c:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/development/php/codeigniter/php-project-simple-task-board/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Project: My Trip Emission</title>
		<link>http://oscardias.com/development/php/php-project-my-trip-emission/</link>
		<comments>http://oscardias.com/development/php/php-project-my-trip-emission/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 16:45:05 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[CO2 emission]]></category>
		<category><![CDATA[global warming]]></category>
		<category><![CDATA[Google Maps]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=216</guid>
		<description><![CDATA[After my one year trip to Australia I&#8217;m back to Brazil. It&#8217;s time to get this blog back to life. So, I&#8217;m going to start writing about a PHP application I did a few years ago called My Trip Emission. It is an application that give you the emission of CO2 of your trip, all [...]]]></description>
			<content:encoded><![CDATA[<p><em>After my one year trip to Australia I&#8217;m back to Brazil. It&#8217;s time to get this blog back to life. So, I&#8217;m going to start writing about a PHP application I did a few years ago called My Trip Emission. It is an application that give you the emission of CO2 of your trip, all you need is to define the model of your car and your trip (from and to). It is developed in pure PHP with jQuery and the Google Maps API.</em></p>
<p><span id="more-216"></span></p>
<h1>Introduction</h1>
<p>My Trip Emission is (or was &#8211; it is not a domain anymore) an application that I developed that allows the user to detect the emission of CO2 base on a Google Maps trip and the selection of a car. It was developed in pure PHP and uses the Google Maps API. I&#8217;ll go through the directory structure and then explain the most important parts. Please note that this is an old project that haven&#8217;t been updated in a while, which means some parts of the code are using old versions of PHP/jQuery/Google Maps API.</p>
<p style="text-align: center;"><a href="http://oscardias.com/wp-content/uploads/2012/04/mytripemission.png"><img class="size-medium wp-image-225 aligncenter" title="MyTripEmission" src="http://oscardias.com/wp-content/uploads/2012/04/mytripemission-300x147.png" alt="MyTripEmission" width="300" height="147" /></a></p>
<p class="downloadnote">You can download the complete project <a title="MyTripEmission Files" href="http://oscardias.com/wp-content/uploads/2012/04/mytripemission.zip">here</a>.</p>
<h1>Directory Structure</h1>
<p>This is a very simple project, with a few files, so I&#8217;m going to show most of them.</p>
<ul class="directory">
<li class="directory">css</li>
<ul class="directory">
<li class="cssfile">bkp_style.css</li>
<li class="cssfile">style.css</li>
<li class="cssfile">styleIE.css</li>
</ul>
<li class="directory">images</li>
<li class="directory">include</li>
<ul class="directory">
<li class="phpfile">config.php</li>
</ul>
<li class="directory">js</li>
<ul class="directory">
<li class="genericfile">jquery_cookies.js</li>
<li class="genericfile">scripts.js</li>
</ul>
<li class="phpfile">about.php</li>
<li class="phpfile">contact.php</li>
<li class="phpfile">contact_sent.php</li>
<li class="genericfile">favicon.ico</li>
<li class="phpfile">get_emission.php</li>
<li class="phpfile">get_model.php</li>
<li class="phpfile">get_version.php</li>
<li class="phpfile">help.php</li>
<li class="phpfile">index.php</li>
<li class="genericfile">mytripemission.sql</li>
<li class="genericfile">robots.txt</li>
<li class="genericfile">sitemap.xml</li>
</ul>
<h2>CSS Folder</h2>
<p>This folder includes three files. bkp_style.css and style.css are the same file, but style.css is minified. styleIE.css has IE specific styling. I&#8217;m not going to explain the details of the styling here. If you want to know more about it, let me know in the comments.</p>
<h2>Images Folder</h2>
<p>Just images&#8230;</p>
<h2>Include Folder</h2>
<p>The include folder contains the config.php file, which handles the database connection. You need to update this file with your database info. Furthermore, this file defines two functions cleanInput($input) and sanitize($input) which are responsible for cleaning the GET variable and ensuring no bad inputs will go to the database.</p>
<pre class="brush: php; title: ; notranslate">
// Database information
$db_user = 'root';
$db_pass = '';
$db_host = 'localhost';
$db_name = 'mytripemission';

// Database connection
$dbc = mysql_connect($db_host, $db_user, $db_pass) OR die('It was not possible to connect to MySQL: ' . mysql_error());
mysql_select_db ($db_name) OR die('It was not possible to select the database: ' . mysql_error());

define('BASE_URL', 'http://localhost/mytripemission/');

// Cleaning function
function cleanInput($input) {

    $search = array(
        '@]*?&gt;.*?@si',   // Strip out javascript
        '@]*?&gt;@si',            // Strip out HTML tags
        '@]*?&gt;.*?@siU',    // Strip style tags properly
        '@@'         // Strip multi-line comments
    );

    $output = preg_replace($search, '', $input);
    return $output;
}
// Sanitizing function
function sanitize($input) {
    if (is_array($input)) {
        foreach($input as $var=&gt;$val) {
            $output[$var] = sanitize($val);
        }
    }
    else {
        if (get_magic_quotes_gpc()) {
            $input = stripslashes($input);
        }
        $input  = cleanInput($input);
        $output = mysql_real_escape_string($input);
    }
    return $output;
}
</pre>
<h2>JS Folder</h2>
<p>Contains the JavaScript files. jquery_cookies.js is a cookie plugin for jQuery developed by Klaus Hartl. It is used on the other file in this folder, scripts.js. This file handles different things and is important for the overall functionality, so lets go through it.<br />
The first part is based on the Google Maps API examples and handles the map generation and events.</p>
<pre class="brush: jscript; title: ; notranslate">
var map;
var gdir;

function initialize() {
  if (GBrowserIsCompatible()) {
    map = new GMap2(document.getElementById(&quot;map_canvas&quot;));
    map.setCenter(new GLatLng(geoip_latitude(), geoip_longitude()), 10);
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.enableScrollWheelZoom();
    gdir = new GDirections(map, document.getElementById(&quot;directions&quot;));
    GEvent.addListener(gdir, &quot;load&quot;, onGDirectionsLoad);
    GEvent.addListener(gdir, &quot;error&quot;, handleErrors);
  }
}

function setDirections(fromAddress, toAddress, locale) {
  gdir.load(&quot;from: &quot; + fromAddress + &quot; to: &quot; + toAddress,
            { &quot;locale&quot;: locale });
}

function handleErrors(){
       if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
         alert(&quot;No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: &quot; + gdir.getStatus().code);

       else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
         alert(&quot;A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: &quot; + gdir.getStatus().code);

       else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
         alert(&quot;The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: &quot; + gdir.getStatus().code);

       else if (gdir.getStatus().code == G_GEO_BAD_KEY)
         alert(&quot;The given key is either invalid or does not match the domain for which it was given. \n Error code: &quot; + gdir.getStatus().code);

       else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
         alert(&quot;A directions request could not be successfully parsed.\n Error code: &quot; + gdir.getStatus().code);

       else alert(&quot;An unknown error occurred.&quot;);

}

function onGDirectionsLoad(){
    distance = gdir.getDistance().meters;

    // Get value for emission
    $.ajax({
        type: 'GET',
        url: 'get_emission.php',
        data: 'manufact=' + $('#manufact').val() + '&amp;model=' + $('#model').val() +
              '&amp;version=' + $('#version').val() + '&amp;meters=' + distance +
              '&amp;fuel_uom=' + $.cookie('fuel_uom'),
        success: function(result){
            $('#emissions').html(result);
        }
    });
}
</pre>
<p>The function setDirections(fromAddress, toAddress, locale) loads the new trip definition. The other function which is interesting here is onGDirectionsLoad() because it calls the calculation of the emission using AJAX and displays it in the sidebar. Next we will continue in the same file.</p>
<pre class="brush: jscript; title: ; notranslate">
/*
 * jQuery
 */
function setError(field) {
    if($(field).val() == 0) {
        $(field).animate({
        backgroundColor: 'red'
            }, 1000, function() {
            $(field).animate({
            backgroundColor: '#FFD1D1'
            }, 1000);
        });

        return false;
    }
    else {
        $(field).css('background-color','white');
        return true;
    }
}

function executeForm() {
    var ok = true;

    ok = setError('#manufact');
    ok = setError('#model');
    ok = setError('#version');
    ok = setError('#fromAddress');
    ok = setError('#toAddress');

    if(!ok) return false;

    // Set cookies
    $.cookie('manufacturer',$('#manufact').val(), { expires: 30 });
    $.cookie('model',$('#model').val(), { expires: 30 });
    $.cookie('version',$('#version').val(), { expires: 30 });
    $.cookie('fromAddress',$('#fromAddress').val(), { expires: 30 });
    $.cookie('toAddress',$('#toAddress').val(), { expires: 30 });

    // Define directions according to language
    if($.cookie('language')){
        setDirections($('#fromAddress').val(), $('#toAddress').val(), $.cookie('language'));
    } else {
        setDirections($('#fromAddress').val(), $('#toAddress').val(), 'en_US');
    }

    return false;
}

function changeUom() {
    if ($.cookie('fuel_uom') == 'km/l') {
        $.cookie('fuel_uom','mpg_US', { expires: 180 });
    } else if ($.cookie('fuel_uom') == 'mpg_US') {
        $.cookie('fuel_uom','mpg_UK', { expires: 180 });
    } else if ($.cookie('fuel_uom') == 'mpg_UK') {
        $.cookie('fuel_uom','km/l', { expires: 180 });
    }

    $.ajax({
        type: 'GET',
        url: 'get_emission.php',
        data: 'manufact=' + $('#manufact').val() + '&amp;model=' + $('#model').val() +
            '&amp;version=' + $('#version').val() + '&amp;meters=' + distance +
            '&amp;fuel_uom=' + $.cookie('fuel_uom'),
        success: function(result){
            $('#emissions').html(result);
        }
    });
}
</pre>
<p>This section has other two important functions. The function executeForm() will check for errors in the form, define cookies (so the user won&#8217;t need to define the information again next time he visits the site) and execute the setDirections(), which will run the Google Maps API.<br />
The second function is changeUom(), which updates the unity of measure cookie and does an AJAX call to update the emissions HTML in the sidebar. The next part of the code is a jQuery event handler.</p>
<pre class="brush: jscript; title: ; notranslate">
// Change window and DIV's width and height on resize
$(window).resize(
    function(){
        $('#container').css('height',($(window).height()-26)+'px');
        if($(window).width() &gt; 734){
            $('#container').css('width',($(window).width()-3)+'px');
        } else {
            $('#container').css('width','730px');
        }
        $('#sidebar').css('height',($('#container').height()-$('#header').height())+'px');
        $('#directions').css('height',($('#sidebar').height()-150)+'px');
        $('#map_canvas').css('height',($('#container').height()-$('#header').height())+'px');
        $('#map_canvas').css('width',($('#container').width()-310)+'px');
    }
);
</pre>
<p>It resizes the map container, in order to make it fit the screen area properly. Finally we arrive at the document ready event, which initializes some things and adds events.</p>
<pre class="brush: jscript; title: ; notranslate">
$(document).ready(function(){
    // Hide scrollbars
    $(&quot;body&quot;).css(&quot;overflow&quot;, &quot;hidden&quot;);

    // Initialize window and DIV's width and height
    $('#container').css('height',($(window).height()-26)+'px');
    if($(window).width() &gt; 734){
        $('#container').css('width',($(window).width()-3)+'px');
    } else {
        $('#container').css('width','730px');
    }
    $('#sidebar').css('height',($('#container').height()-$('#header').height())+'px');
    $('#directions').css('height',($('#sidebar').height()-150)+'px');
    $('#map_canvas').css('height',($('#container').height()-$('#header').height())+'px');
    $('#map_canvas').css('width',($('#container').width()-310)+'px');

    // Settings dialog
    $(&quot;#settings&quot;).dialog({
      bgiframe: true, autoOpen: false, height: 60, width: 400, modal: false, closeOnEscape: true
    });

    // Initialize settings from cookies
    if($.cookie('fuel_uom')) {
        $('#fuel_uom').val($.cookie('fuel_uom'));
    } else {
        $.cookie('fuel_uom', 'mpg_US', { expires: 180 });
    }

    if($.cookie('language')) {
        $('#language').val($.cookie('language'));
    } else {
        $.cookie('language', 'en_US', { expires: 180 });
    }

    // Initialize values - get cookies
    if($.cookie('manufacturer')) {
        $('#manufact').val($.cookie('manufacturer'));

        $.ajax({
            type: 'GET',
            url: 'get_model.php',
            data: 'manufact=' + $('#manufact').val(),
            success: function(result){
                $('#model').children().remove();
                $('#model').append('- Select -')
                           .append(result)
                           .removeAttr('disabled');

                if($.cookie('model')) {
                    $('#model').val($.cookie('model'));

                    $.ajax({
                        type: 'GET',
                        url: 'get_version.php',
                        data: 'manufact=' + $('#manufact').val() + '&amp;model=' + $('#model').val(),
                        success: function(result){
                            $('#version').children().remove();
                            $('#version').append('- Select -')
                                         .append(result)
                                         .removeAttr('disabled');

                            if($.cookie('version')) {
                                $('#version').val($.cookie('version'));
                            }
                        }
                    });
                }
            }
        });
    }

    // Vehicle selection ajax
    $('#manufact').change(
        function() {
            $.ajax({
                type: 'GET',
                url: 'get_model.php',
                data: 'manufact=' + $(this).val(),
                success: function(result){
                    $('#model').children().remove();
                    $('#model').append('- Select -')
                               .append(result)
                               .removeAttr('disabled');
                    $('#version').children().remove();
                    $('#version').append('- Select -')
                                 .attr('disabled', 'disabled');
                }
            });
        });

    $('#model').change(
        function() {
            $.ajax({
                type: 'GET',
                url: 'get_version.php',
                data: 'manufact=' + $('#manufact').val() + '&amp;model=' + $(this).val(),
                success: function(result){
                    $('#version').children().remove();
                    $('#version').append('- Select -')
                                 .append(result)
                                 .removeAttr('disabled');
                }
            });
        });

    // Check my trip button
    $('#check_btn').click(
        function() {
            return executeForm();
        });

    // Fuel unit of measure Cookie
    $('#fuel_uom').change(
        function() {
            $.cookie('fuel_uom',$('#fuel_uom').val(), { expires: 180 });
        });

    // Language Cookie
    $('#language').change(
        function() {
            $.cookie('language',$('#language').val(), { expires: 180 });
        });
});
</pre>
<p>First I initialize different things:</p>
<ul>
<li>Hide body scroll bars;</li>
<li>Initialize map size;</li>
<li>Define settings dialog;</li>
<li>Initialize values according to cookies.</li>
</ul>
<p>The cookies manufacturer, model and version are initialized one after the other, because they depend on each other. So, first we get the manufacturer. Than we check the database and the cookie for the model. Finally we check the database again and the cookie for the version.<br />
Next, we have the Vehicle selection AJAX calls. When we change one of the dropdowns, we check the database to fill the options of the other dropdowns.<br />
Lastly, we have events for the &#8220;Check my Trip&#8221; button and the settings dialog screen, with the unit of measure and language changes. Now let&#8217;s go to the root folder and talk about the PHP itself.</p>
<h2>Root Folder</h2>
<p>The root folder contains simple files like about.php (basic information about the site), contact.php and contact_sent.php (the contact form and it&#8217;s answer), favicon.ico (site icon), help.php (information on how to use the website), mytripemission.sql (database creation script), robots.txt (defines where the search engine can go) and the sitemap.xml. I&#8217;m only go through the other files, which are more interesting.</p>
<h3>index.php</h3>
<p>The index file has the HTML for the main page. Besides the form, which handles the search, it also defines the main DIVs used by the JavaScript. In this file I also use the BASE_URL constant which is defined in the config.php file. You need to remember to update this if you want the application to run.</p>
<h3>get_model.php and get_version.php</h3>
<p>Both files are called via AJAX and are simple database queries, getting information to fill the dropdowns in the index.php file.<br />
<strong>get_model.php</strong></p>
<pre class="brush: php; title: ; notranslate">
require_once 'include/config.php';

$_GET = sanitize($_GET);

$sql = 'SELECT id, name FROM model WHERE manufacturer='.$_GET['manufact'];
$res = mysql_query($sql);
while($row = mysql_fetch_array($res)) {
    echo ''.$row['name'].'';
}
</pre>
<p><strong>get_version.php</strong></p>
<pre class="brush: php; title: ; notranslate">
require_once 'include/config.php';

$_GET = sanitize($_GET);

$sql = 'SELECT id, name, trans_type FROM version
        WHERE manufacturer='.$_GET['manufact'].'
          AND model='.$_GET['model'];
$res = mysql_query($sql);
while($row = mysql_fetch_array($res)) {
    if($row['trans_type'] == 'M') {
        $transmission_type = 'Manual';
    } elseif($row['trans_type'] == 'A') {
        $transmission_type = 'Automatic';
    } else {
        $transmission_type = '';
    }

    echo ''.$row['name'].' '. $transmission_type.'';
}
</pre>
<h3>get_emission.php</h3>
<p>This is the file that really does the trick. This file I&#8217;m going to explain step by step.</p>
<pre class="brush: php; title: ; notranslate">
require_once 'include/config.php';

// Get emisison logic
$_GET = sanitize($_GET);

$fuel_uom = $_GET['fuel_uom'];
$distance = $_GET['meters'];

$vehicle = explode('-', $_GET['version']);
$version = $vehicle[0];
$trans_type = $vehicle[1];
</pre>
<p>First, we require the config file, which does the database connection and defines the sanitize() function. Then we start the emission logic by sanitizing the $_GET variable and assigning the fuel unit of measure, the distance and the vehicle, which includes the version and transmission type.</p>
<pre class="brush: php; title: ; notranslate">
// Get values for calulating vehicle green stars
$sql_stars = 'SELECT MAX( emission_co2 ) AS worse, MIN( emission_co2 ) AS best FROM version';
$res_stars = mysql_query($sql_stars) or die('Database error!');
$row_stars = mysql_fetch_array($res_stars);
$worse = $row_stars['worse'];
$best = $row_stars['best'];
$star_rate = ($worse - $best)/5; // Rate for each star
</pre>
<p>The code continues defining what will be a 5 star emission. For this purpose we fetch the MAX and MIN emissions from the database and define a $star_rate based on these values.</p>
<pre class="brush: php; title: ; notranslate">
$sql = 'SELECT kml_urban, kml_extra, kml_combined, emission_co2
        FROM version
        WHERE manufacturer='.$_GET['manufact'].'
          AND model='.$_GET['model'].'
          AND id='.$version.'
          AND trans_type=\''.$trans_type.'\'';

$res = mysql_query($sql) or die($version.'-'.$trans_type);

$change_link = '
';

if ($row = mysql_fetch_array($res)) {
// This code is in the next code block
}
</pre>
<p>Next, we get the information for the selected vehicle. As we are going to return an HTML code, we also define the $change_link, responsible for changing the unit of measure. The next chunk of code is inside the last IF statement.</p>
<pre class="brush: php; title: ; notranslate">
    $litres = round(($distance/1000) / $row['kml_combined'], 2);
    $co2 = round((($distance/1000) * $row['emission_co2'])/1000, 2);
    $stars_num = round(($worse-$row['emission_co2'])/$star_rate, 0);
    if ($stars_num == 1) {
        $stars_txt = ' Star';
    } else {
        $stars_txt = ' Stars';
    }

    // Change unit of measure

    if ($fuel_uom == 'km/l') {
        echo '&lt;/pre&gt;
&lt;h1&gt;Consumption&lt;/h1&gt;
&lt;pre&gt; '.$litres.' litres ('.$row['kml_combined'].' km/l)';
        echo $change_link;
        echo '&lt;/pre&gt;
&lt;h1&gt;CO2 Emission&lt;/h1&gt;
&lt;pre&gt; '.$co2.' kg ('.$row['emission_co2'].' g/km)';
    } else if ($fuel_uom == 'mpg_US') {
        $gallons = round($litres * 0.264, 2);
        $mpg = round($row['kml_extra'] / 0.425, 2);
        echo '&lt;/pre&gt;
&lt;h1&gt;Consumption&lt;/h1&gt;
&lt;pre&gt; '.$gallons.' gallons ('.$mpg.' MPG (US))';
        echo $change_link;
        echo '&lt;/pre&gt;
&lt;h1&gt;CO2 Emission&lt;/h1&gt;
&lt;pre&gt; '.$co2.' kg ('.$row['emission_co2'].' g/km)';
    } else if ($fuel_uom == 'mpg_UK') {
        $gallons = round($litres * 0.220, 2);
        $mpg = round($row['kml_extra'] / 0.354, 2);
        echo '&lt;/pre&gt;
&lt;h1&gt;Consumption&lt;/h1&gt;
&lt;pre&gt; '.$gallons.' gallons ('.$mpg.' MPG (Imp))';
        echo $change_link;
        echo '&lt;/pre&gt;
&lt;h1&gt;CO2 Emission&lt;/h1&gt;
&lt;pre&gt; '.$co2.' kg ('.$row['emission_co2'].' g/km)';
    }

    echo '&lt;span class=&quot;fltrt&quot;&gt;';
 for ($i = 5; $i &gt;= 1; $i--) {
 if ($i echo '&lt;img title=&quot;'.$stars_num.$stars_txt.'&quot; src=&quot;'.BASE_URL.'images/star.png&quot; alt=&quot;'.$stars_num.$stars_txt.'&quot; /&gt;';
 } else {
 echo '&lt;img title=&quot;'.$stars_num.$stars_txt.'&quot; src=&quot;'.BASE_URL.'images/star_black.png&quot; alt=&quot;'.$stars_num.$stars_txt.'&quot; /&gt;';
 }

 }
 echo '&lt;/span&gt;';
</pre>
<p>Finally, in this part of the code we start by calculating the consumption ($litres) and emission ($co2). Note that the distance is divided by 1000, to get the km. We also calculate the number of stars for the current emission, this way we can give a rating to the vehicle emission.<br />
Continuing, after the &#8220;Change unit of measure&#8221; comment, we check which unit of measure is selected and create the HTML accordingly. To conclude the HTML, we also echo a SPAN tag, containing the star rating.</p>
<h1>Conclusion</h1>
<p>So, this what I had to show in this reactivation of my blog. This small project was online until last year, and I thought I should make it available in case anyone is interested. When I did it I had the intention to add more data and make it really usable, but in the end I changed my priorities&#8230; Anyway, it is available here totally free and open, but if you use it, don&#8217;t forget to reference this blog post.<br />
Next week I&#8217;m going to (try to) write about a task board application that I developed using CodeIgniter. It is already <a title="Simple Task Board" href="https://github.com/oscardias/Simple-Task-Board">available at GitHub</a>, in case you&#8217;re interested.</p>
<p class="downloadnote">You can download the complete project <a title="MyTripEmission Files" href="http://oscardias.com/wp-content/uploads/2012/04/mytripemission.zip">here</a>.</p>
<div class="simplenote"><strong>References:</strong><br />
<a title="Google Maps API" href="https://developers.google.com/maps/">Google Maps API</a></p>
<p>VCACarfueldata &#8211; now <a title="VCS Offices" href="http://www.dft.gov.uk/vca/fcb/carfueldata-tools-redirect-page.asp">here</a></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=Cxo8j9_3or8:93e2xFcwhtw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=Cxo8j9_3or8:93e2xFcwhtw:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=Cxo8j9_3or8:93e2xFcwhtw:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=Cxo8j9_3or8:93e2xFcwhtw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/development/php/php-project-my-trip-emission/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating WordPress with CodeIgniter</title>
		<link>http://oscardias.com/development/php/codeigniter/integrating-wordpress-with-codeigniter/</link>
		<comments>http://oscardias.com/development/php/codeigniter/integrating-wordpress-with-codeigniter/#comments</comments>
		<pubDate>Sat, 02 Jul 2011 15:07:32 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[users]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=178</guid>
		<description><![CDATA[After a long time since my last post, I&#8217;m going to start writing again. My focus on the next articles will be CodeIgniter. The first thing I want to show is how to integrate CodeIgniter with WordPress. More precisely, I&#8217;m going to show how to use WordPress users inside CodeIginter. The motivation for this is [...]]]></description>
			<content:encoded><![CDATA[<p><em>After a long time since my last post, I&#8217;m going to start writing again. My focus on the next articles will be CodeIgniter. The first thing I want to show is how to integrate CodeIgniter with WordPress. More precisely, I&#8217;m going to show how to use WordPress users inside CodeIginter. The motivation for this is that you won&#8217;t need to handle user authentication inside your application.</em></p>
<p><span id="more-178"></span></p>
<h1>Introduction</h1>
<p><a href="http://www.codeigniter.com">CodeIgniter</a> is a PHP framework with a small footprint desgned to aid the development of customized web applications. It is a MVC framework that provides the main structure in which we build our custom logics. But if you already have a WordPress website and you want to create, for example, a CRM application using CodeIgniter, it would be good to reuse some features from WordPress. One of these features is the user management. In WordPress we have user details, authentication, user levels, etc. So, in this article I&#8217;m going to show how to do this.</p>
<p class="simplenote">In this article I&#8217;m using CodeIgniter 2.0.2 and WordPress 3.2.</p>
<h1>Preparing our CodeIgniter Application</h1>
<p>If you haven&#8217;t downloaded CodeIgniter yet, please do it in this <a href="http://codeigniter.com/downloads/">link</a>. Extract the file contents to your WordPress root and rename the <em>CodeIgniter_2.0.2</em> folder to your desired name. As it will be inside WordPress, it will be accessed like <em>www.youdomain.com/wordpress/codeigniter</em>. You need to take care of the name you choose because it may collide with WordPress categories. You may need to customise your <em>.htaccess</em> file in order to make your application accessible.</p>
<p>You probably could create your CodeIgniter application outside your WordPress folder. But you would need to customize the users cookie path in a way that WordPress functions would work.</p>
<p>Now let&#8217;s start coding.</p>
<h1>WP Integration Library</h1>
<p>There are different ways to achieve what we want. One of them would be to create a Helper file and define different functions inside that helper. The other option is to create it using the object oriented approach which requires a library file that defines a class. The last one is the option I&#8217;m going to show here. So, let&#8217;s build the library step by step.</p>
<h3>Step 1 &#8211; File and Class Declaration</h3>
<p>First thing we need to do is to create a new file called <em>Wpintegration.php</em> inside the folder <em>application/libraries</em>. Then we need to define our class inside this file:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* WordPres Integration Class
*
* This class enables the use of wordpress functions
*
* @author		Oscar Dias
* @link		http://oscardias.com/codeigniter/integrating-wordpress-with-codeigniter
*/
class Wpintegration {

    //
    // Our code goes here!!!
    //

}
/* End of file Wpintegration.php */
</pre>
<h3>Step 2 &#8211; Class Constructor</h3>
<p>We are going to define a constructor for our class. This constructor will define some global variables (used by WordPress functions) and will include the <em>wp-load.php</em> file. This file will initiate the entire WordPress application. I left some additional variables that I found during my tests commented inside the method. I&#8217;m not sure, but I think that if you use different functions you will need different variables&#8230;</p>
<pre class="brush: php; title: ; notranslate">
    public function __construct() {
        global $table_prefix, $wp_embed, $wp_widget_factory, $_wp_deprecated_widgets_callbacks, $wp_locale, $wp_rewrite;
        // Additional WordPress global variables
        //$wpdb, $current_user, $auth_secure_cookie, $wp_roles, $wp_the_query, $wp_query, $wp, $_updated_user_settings,
        //$wp_taxonomies, $wp_filter, $wp_actions, $merged_filters, $wp_current_filter, $wp_registered_sidebars,
        //$wp_registered_widgets, $wp_registered_widget_controls, $wp_registered_widget_updates, $_wp_deprecated_widgets_callbacks,
        //$posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_version, $id, $comment, $user_ID;

        require_once '../wp-load.php';
    }
</pre>
<h3>Step 3 &#8211; Methods for User Management</h3>
<p>In order to complete our class, we are going to define some methods to return user information. What we want to get from WordPress is if the user is logged in, if the user is super admin and the following links: login, logout, blog and WordPress admin section.</p>
<ul>
<li>The first method we&#8217;re creating is the <em>isLoggedIn()</em>. It is a very simple method that will just return the WordPress function <em>is_user_logged_in()</em>. As you can imagine, it will be true or false.
<pre class="brush: php; title: ; notranslate">
    public function isLoggedIn()
    {
        return is_user_logged_in();
    }
</pre>
</li>
<li>Next, we need a method to say when a user is super admin. We are using the function <em>wp_ge_current_user()</em> and returning true when the user level is greater than 10. You could simply return the user level and handle the different user levels inside your CodeIgniter application. In my case I was only interested in knowing if the user is a super admin.
<pre class="brush: php; title: ; notranslate">
    public function isSuperAdmin()
    {
        if(wp_get_current_user()-&gt;user_level &gt;= 10)
            return true;
        else
            return false;
    }
</pre>
</li>
<li>The methods <em>loginLink()</em> and <em>logoutLink()</em> will return the login and logout links for our website. These links will take you to the WordPress login and logout pages, but they have a redirect_to query string, which will contain the link to our application. So, after you login (or logout), you will be redirected back to the CodeIgniter app. Notice that in these methods we use the CodeIgniter instance to load a helper. The helper is <em>&#8216;ci_url&#8217;</em>, which is a copy of the original CodeIgniter URL helper with a few changes that I&#8217;m going to explain later. The function <em>current_url()</em> is defined inside this helper.
<pre class="brush: php; title: ; notranslate">
    public function loginLink()
    {
        $CI = &amp; get_instance();
        $CI-&gt;load-&gt;helper('ci_url');
        $redirect = current_url();

        return wp_login_url().&quot;?redirect_to=$redirect&quot;;
    }

    public function logoutLink()
    {
        $CI = &amp; get_instance();
        $CI-&gt;load-&gt;helper('ci_url');
        $redirect = current_url();

        return wp_logout_url().&quot;&amp;redirect_to=$redirect&quot;;
    }
</pre>
</li>
<li>The next two methods are quite the same. They will return the links for our WordPress blog and for the admin section. This would be useful to link directly to them from our application.
<pre class="brush: php; title: ; notranslate">
    public function blogLink()
    {
        return get_option('siteurl');
    }

    public function adminLink()
    {
        return get_option('siteurl') . &quot;/wp-admin&quot;;
    }
</pre>
</li>
</ul>
<h1>Changes in CodeIgniter</h1>
<p>In the moment that we include <em>wp-load.php</em>, several functions are included with it. So we need to take care with possible conflicts caused by function redefinition. As an example of conflicts, I&#8217;m going to use the CodeIgniter URL helper. This helper has the functions <em>site_url()</em> and <em>base_url()</em>, which also exists inside WordPress. So, I just copied the complete helper to the helper folder inside our application. Then I changed the functions that were conflicting, renaming them to <em>ci_site_url()</em> and <em>ci_base_url()</em>. We also need to change where these two functions are used, inside the <em>anchor()</em>, <em>anchor_popup()</em> and <em>redirect()</em> functions. I used the URL helper as an example of the changes needed to make it work. But depending on what you need, you may need to customize different functions.</p>
<h1>Conclusion</h1>
<p>This integration is not natural and clean, as WordPress and CodeIgniter are obviously not built to work together. But it is quite interesting to be able to create a web application with the possibility of reusing WordPress features. Hope it helps someone. If you have any ideas or comments, leave your message.</p>
<p class="updatenote">When I wrote this article, WordPress 3.2 was not available. So I needed to do some changes inside WordPress to make the integration work. After downloading version 3.2 it became easier to do the integration. So I updated the article accordingly.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=JEjxtb3wIyI:cwhY7iEdJB0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=JEjxtb3wIyI:cwhY7iEdJB0:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=JEjxtb3wIyI:cwhY7iEdJB0:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=JEjxtb3wIyI:cwhY7iEdJB0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/development/php/codeigniter/integrating-wordpress-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to Add a Rate Field to WordPress Comments</title>
		<link>http://oscardias.com/development/php/wordpress/how-to-add-a-rate-field-to-wordpress-comments/</link>
		<comments>http://oscardias.com/development/php/wordpress/how-to-add-a-rate-field-to-wordpress-comments/#comments</comments>
		<pubDate>Tue, 28 Sep 2010 21:39:43 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[comment meta]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[rate]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=160</guid>
		<description><![CDATA[In this article I'll show you how to add a rating field to your WordPress comments. We'll work with PHP to enable the new field and show it in the comments template. Also, we're going to do some styling in order to give a nice look to the rate system. Finally we'll also create a small JavaScript using jQuery to enable it.]]></description>
			<content:encoded><![CDATA[<p><em>In this article I&#8217;ll show you how to add a rating field to your WordPress comments. We&#8217;ll work with PHP to enable the new field and show it in the comments template. Also, we&#8217;re going to do some styling in order to give a nice look to the rate system. Finally we&#8217;ll also create a small JavaScript using jQuery to enable it.</em></p>
<p><span id="more-160"></span></p>
<h1>Introduction</h1>
<p>In this article we&#8217;ll create the rating system in four steps:</p>
<ul>
<li>Add the comment meta data</li>
<li>Update the comments template</li>
<li>Add new CSS styles</li>
<li>Add new JavaScript</li>
<li>How to Get the Rating Average (update)</li>
</ul>
<p>So, let&#8217;s begin.</p>
<h2>Comment Meta Data</h2>
<p>The first thing we need to do is to open our <em>functions.php</em> file and add the following code:</p>
<pre class="brush: php; title: ; notranslate">
add_action('comment_post','comment_ratings');

function comment_ratings($comment_id) {
    add_comment_meta($comment_id, 'rate', $_POST['rate']);
}
</pre>
<p>As you can see it&#8217;s pretty simple. We&#8217;re adding a action to be executed when the comment is posted. Inside the function <em>comment_ratings</em>, we&#8217;re adding the new information to the comment meta data. In this case I&#8217;m adding the field <em>rate</em> with the value of the field <em>rate</em> that was posted.</p>
<p>Now we need to add the field <em>rate</em> to the comment template.</p>
<h2>Comments Template</h2>
<p>We need to add the field in two places: where we display the comments and where the visitor enter his comment. As we already have the <em>functions.php</em> file opened, let&#8217;s add the following function (it&#8217;s the same function from the WordPress Codex, with the additional rate field):</p>
<pre class="brush: php; title: ; notranslate">
function comment_template($comment, $args, $depth) {
    $GLOBALS['comment'] = $comment; ?&gt;
    &lt;li &lt;?php comment_class(); ?&gt; id=&quot;li-comment-&lt;?php comment_ID() ?&gt;&quot;&gt;
        &lt;div id=&quot;comment-&lt;?php comment_ID(); ?&gt;&quot;&gt;
            &lt;div class=&quot;comment-author vcard&quot;&gt;
                &lt;?php echo get_avatar($comment,$size='48'); ?&gt;

                &lt;?php printf(__('&lt;cite class=&quot;fn&quot;&gt;%s&lt;/cite&gt; &lt;span class=&quot;says&quot;&gt;says:&lt;/span&gt;'), get_comment_author_link()) ?&gt;
            &lt;/div&gt;

            &lt;?php if ($comment-&gt;comment_approved == '0') : ?&gt;
            &lt;em&gt;&lt;?php _e('Your comment is awaiting moderation.') ?&gt;&lt;/em&gt;
            &lt;br /&gt;
            &lt;?php endif; ?&gt;

            &lt;div class=&quot;comment-meta commentmetadata&quot;&gt;&lt;a href=&quot;&lt;?php echo htmlspecialchars( get_comment_link( $comment-&gt;comment_ID ) ) ?&gt;&quot;&gt;&lt;?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?&gt;&lt;/a&gt;&lt;?php edit_comment_link(__('(Edit)'),'  ','') ?&gt;&lt;/div&gt;

            &lt;?php
            $rate = get_comment_meta($comment-&gt;comment_ID, 'rate');
            if ($rate[0] &lt;&gt; '') {
                _e('Grade: ');
                echo movie_grade($rate[0]);
            }
            ?&gt;

            &lt;?php comment_text() ?&gt;

            &lt;div class=&quot;reply&quot;&gt;
                &lt;?php comment_reply_link(array_merge( $args, array('depth' =&gt; $depth, 'max_depth' =&gt; $args['max_depth']))) ?&gt;
            &lt;/div&gt;
        &lt;/div&gt;
&lt;?php
}
</pre>
<p>This function will be used to display the comments list. We added here a call to the <em>get_comment_meta</em> function. It will return an array with the rate information. If it&#8217;s empty, we&#8217;ll not display anything. If it&#8217;s not, then we&#8217;ll show it using the following function:</p>
<pre class="brush: php; title: ; notranslate">
function movie_grade($grade) {
    switch ($grade) {
        case '0':
            $alt = 'Zero - 0 stars';
            break;
        case '1':
            $alt = 'Really bad - 1 star';
            break;
        case '2':
            $alt = 'Bad - 2 stars';
            break;
        case '3':
            $alt = 'Good - 3 stars';
            break;
        case '4':
            $alt = 'Very good - 4 stars';
            break;
        case '5':
            $alt = 'Excellent - 5 stars';
            break;
        default:
            $alt = 'No grade';
            break;
    }

    if (!isset($grade) || $grade == '')
        echo $alt;
    else {
        for ($i = 0; $i &lt; 5; $i++) {
            if ($grade &gt; $i)
                echo '&lt;img src=&quot;'.get_stylesheet_directory_uri().'/images/star_on.png&quot; alt=&quot;'.$alt.'&quot; title=&quot;'.$alt.'&quot; /&gt;';
            else
                echo '&lt;img src=&quot;'.get_stylesheet_directory_uri().'/images/star_off.png&quot; alt=&quot;'.$alt.'&quot; title=&quot;'.$alt.'&quot; /&gt;';
        }
    }
}
</pre>
<p>In this function we&#8217;re displaying images according to the rate posted by the visitors. Last thing we need to do in order to show the rates in the comments list is in the <em>comments.php</em> file. Find the call to <em>wp_list_comments</em> and add the parameter &#8216;type=comment&amp;callback=comment_template&#8217;. It should look like this:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php wp_list_comments('type=comment&amp;callback=comment_template'); ?&gt;
</pre>
<p>This will display the comments list using the callback function <em>comment_template</em> that we created earlier. The next and last thing we need for the comments template is it to update the comment entry. We need to add a <em>rate</em> field there. Let&#8217;s add some image links, to make it more functional.</p>
<pre class="brush: php; title: ; notranslate">
&lt;div&gt;
    &lt;div class=&quot;comment-rating&quot;&gt;
        &lt;ul class=&quot;star-rating&quot;&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;&lt;?php _e('Zero - 0 stars'); ?&gt;&quot; class=&quot;zero-star&quot; onclick=&quot;rateClick(0); return false;&quot;&gt;0&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;&lt;?php _e('Really bad - 1 star'); ?&gt;&quot; class=&quot;one-star&quot; onclick=&quot;rateClick(1); return false;&quot;&gt;1&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;&lt;?php _e('Bad - 2 stars'); ?&gt;&quot; class=&quot;two-stars&quot; onclick=&quot;rateClick(2); return false;&quot;&gt;2&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;&lt;?php _e('Good - 3 stars'); ?&gt;&quot; class=&quot;three-stars&quot; onclick=&quot;rateClick(3); return false;&quot;&gt;3&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;&lt;?php _e('Very good - 4 stars'); ?&gt;&quot; class=&quot;four-stars&quot; onclick=&quot;rateClick(4); return false;&quot;&gt;4&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href=&quot;#&quot; title=&quot;&lt;?php _e('Excellent - 5 stars'); ?&gt;&quot; class=&quot;five-stars&quot; onclick=&quot;rateClick(5); return false;&quot;&gt;5&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
    &lt;?php _e('Your rate'); ?&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;rate&quot; id=&quot;rate&quot; value=&quot;&lt;?php echo esc_attr($comment_author_rate); ?&gt;&quot; /&gt;
&lt;/div&gt;
</pre>
<p>Next we&#8217;ll style the links and add JavaScript to update the hidden input.</p>
<h2>New CSS Styles</h2>
<p>We&#8217;ll create the styles we&#8217;ve used in the HTML. These styles will replace the links with images and use a hover effect. I pretty much copied it from <a href="http://www.komodomedia.com/blog/2005/08/creating-a-star-rater-using-css/">Create a Star Rater using CSS</a>. So, the necessary CSS is:</p>
<pre class="brush: css; title: ; notranslate">
.comment-rating {float:left; width:180px;}
.star-rating,
.star-rating a:hover,
.star-rating a:active,
.star-rating a:focus,
.star-rating .current-rating{background: url(images/star.png) left -1000px repeat-x;}
.star-rating{position:relative;width:108px;height:25px;overflow:hidden;list-style:none;margin:0;padding:0;
             background-position: left top;}
.star-rating li{display: inline;}
.star-rating a,
.star-rating .current-rating{position:absolute;top:0;left:0;text-indent:-1000em;height:25px;line-height:25px;
                             outline:none;overflow:hidden;border: none;}
.star-rating a:hover,
.star-rating a:active,
.star-rating a:focus{background-position: left bottom;}
.star-rating a.one-star{width:34%;z-index:6;}
.star-rating a.two-stars{width:51%;z-index:5;}
.star-rating a.three-stars{width:68%;z-index:4;}
.star-rating a.four-stars{width:85%;z-index:3;}
.star-rating a.five-stars{width:100%;z-index:2;}
.star-rating .current-rating{z-index:1;background-position: left center;}
.star-rating a.zero-star {width:17%;z-index:8;background: url(images/no_star.png) left top no-repeat;}
.star-rating a.zero-star:hover,
.star-rating a.zero-star:active,
.star-rating a.zero-star:focus {background-position: left center;}
.star-rating a.zero-selected {background-position: left center;}
</pre>
<p>We defined here a width of 180px for the hole DIV. It&#8217;s a quick attempt to align it with the other texts. In Chrome it looks OK, but not in Firefox. You may choose an alternative way to align them. Anyway, you&#8217;ll need the following image files:</p>
<ul>
<li><a href="http://oscardias.com/wp-content/uploads/2010/09/star.png">star.png</a></li>
<li><a href="http://oscardias.com/wp-content/uploads/2010/09/no_star.png">no_star.png</a></li>
<li><a href="http://oscardias.com/wp-content/uploads/2010/09/star_on.png">star_on.png</a></li>
<li><a href="http://oscardias.com/wp-content/uploads/2010/09/star_off.png">star_off.png</a></li>
</ul>
<p>It was possible to use the same files, but I was lazy to update the hole thing&#8230; So, after we had created the functions, updated the templates and created the CSS, now it&#8217;s time to create the JavaScript.</p>
<h2>New JavaScript</h2>
<p>We&#8217;re going to use jQuery functions, so you&#8217;ll need to have it enqueued in your blog. In our js file we have two functions. They may not be optimized, but it works <img src='http://oscardias.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<pre class="brush: jscript; title: ; notranslate">
function clearSelected() {
    $('.star-rating a.zero-star').removeClass('zero-selected');
    $('.star-rating a.one-star').removeClass('current-rating');
    $('.star-rating a.two-stars').removeClass('current-rating');
    $('.star-rating a.three-stars').removeClass('current-rating');
    $('.star-rating a.four-stars').removeClass('current-rating');
    $('.star-rating a.five-stars').removeClass('current-rating');
}

function rateClick(num) {
    clearSelected();
    switch (num) {
        case 0:
            $('.star-rating a.zero-star').addClass('zero-selected');
            $('#rate').val('0');
            break;
        case 1:
            $('.star-rating a.one-star').addClass('current-rating');
            $('#rate').val('1');
            break;
        case 2:
            $('.star-rating a.two-stars').addClass('current-rating');
            $('#rate').val('2');
            break;
        case 3:
            $('.star-rating a.three-stars').addClass('current-rating');
            $('#rate').val('3');
            break;
        case 4:
            $('.star-rating a.four-stars').addClass('current-rating');
            $('#rate').val('4');
            break;
        case 5:
            $('.star-rating a.five-stars').addClass('current-rating');
            $('#rate').val('5');
            break;
    }
}
</pre>
<p>In the first function we only clear the selected classes. In the second one we add the selected class and set the hidden input with the correct value.</p>
<h2>How to Get the Rating Average</h2>
<p class="updatenote">This section is an update to this post. Updated in July 27th, 2011.</p>
<p>It is quite easy to calculate the average of ratings posted in your comments. First, we need to add the following function inside our <em>functions.php</em> file:</p>
<pre class="brush: php; title: ; notranslate">
function get_average_ratings($id) {
    $comment_array = get_approved_comments($id);
    $count = 1;

    if ($comment_array) {
        $i = 0;
        $total = 0;
        foreach($comment_array as $comment){
            $rate = get_comment_meta($comment-&gt;comment_ID, 'rate');
            if(isset($rate[0]) &amp;&amp; $rate[0] !== '') {
                $i++;
                $total += $rate[0];
            }
        }

        if($i == 0)
            return false;
        else
            return round($total/$i);
    } else {
        return false;
    }
}
</pre>
<p>This function will get all approved comments for a given post ID and loop through them summing up the total value of the rate field. It will sum up only when the rate field was defined. So, if the user didn&#8217;t defined a rate, it will not be calculated. This function will return the average of ratings or will return false if there are no approved comments.<br />
Later you can call this function in your <em>single.php</em> file. You can use it to first verify if there are ratings. If there are ratings, you can use the function <em>movie_grade()</em> to display it properly. The code to use it could be something like this:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php (get_average_ratings($post-&gt;ID))?movie_grade(get_average_ratings($post-&gt;ID)):'Not available'; ?&gt;
</pre>
<h1>Conclusion</h1>
<p>That&#8217;s all I had to show this time. It&#8217;s possible to use similar functions to create any comment entry template. This way you could not only make your blog unique, but also make the discussion unique. Here is a preview of the result (more or less):</p>
<div id="attachment_170" class="wp-caption alignnone" style="width: 310px"><a href="http://oscardias.com/wp-content/uploads/2010/09/Preview.jpg"><img class="size-medium wp-image-170" title="Rate Comment Preview" src="http://oscardias.com/wp-content/uploads/2010/09/Preview-300x244.jpg" alt="Rate Comment Preview" width="300" height="244" /></a><p class="wp-caption-text">Rate Comment Preview</p></div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=-PqTDDtk-Bc:Uwf9DQyqwqw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=-PqTDDtk-Bc:Uwf9DQyqwqw:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=-PqTDDtk-Bc:Uwf9DQyqwqw:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=-PqTDDtk-Bc:Uwf9DQyqwqw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/development/php/wordpress/how-to-add-a-rate-field-to-wordpress-comments/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Adding Custom Information to WordPress Posts</title>
		<link>http://oscardias.com/development/php/wordpress/adding-custom-information-to-wordpress-posts/</link>
		<comments>http://oscardias.com/development/php/wordpress/adding-custom-information-to-wordpress-posts/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 00:07:31 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[custom fields]]></category>
		<category><![CDATA[custom taxonomies]]></category>
		<category><![CDATA[taxonomy]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=150</guid>
		<description><![CDATA[In this article I'm going to show how to add custom information to your WordPress posts. We'll start with the standard custom fields, very useful if you're the theme developer and the only blogger. Next I'll show you how to create your additional fields. They're work pretty much like the custom fields, but you can add a name and description to them, so your theme users know what to write there. The last thing I'm going to show is the custom taxonomies added in WordPress 3.0.]]></description>
			<content:encoded><![CDATA[<p><em>In this article I&#8217;m going to show how to add custom information to your WordPress posts. We&#8217;ll start with the standard custom fields, very useful if you&#8217;re the theme developer and the only blogger. Next I&#8217;ll show you how to create your additional fields. They&#8217;re work pretty much like the custom fields, but you can add a name and description to them, so your theme users know what to write there. The last thing I&#8217;m going to show is the custom taxonomies added in WordPress 3.0.</em></p>
<p><span id="more-150"></span></p>
<h1>Custom Fields</h1>
<p>The WordPress custom fields allows you to add different information to your post. When you use them you are able to place these fields directly in your theme template and give a standard look to your posts even when you have different bloggers. In the past this feature was used to add post thumbnails, but today we can use the Featured Image. But we can use it for different information like, for example, the difficulty level of your tutorial post.</p>
<p>There are two ways of doing this: the standard one and the customized one.</p>
<h2>Standard Custom Fields</h2>
<p>The standard way of using custom fields are really simple. When you add a new post, you can see after the Excerpt and Send Trackbacks areas a area called Custom Fields. It looks like this:</p>
<div id="attachment_151" class="wp-caption alignnone" style="width: 310px"><a href="http://oscardias.com/wp-content/uploads/2010/09/custom_fields.jpg"><img class="size-medium wp-image-151" title="Standard Custom Fields" src="http://oscardias.com/wp-content/uploads/2010/09/custom_fields-300x82.jpg" alt="Standard Custom Fields" width="300" height="82" /></a><p class="wp-caption-text">Standard Custom Fields</p></div>
<p>As you can see, you&#8217;re able to add as many fields as you want. You just have to name them and set their value. Then you may add them to you theme template by using the function <em><a title="WordPress Codex Reference" href="http://codex.wordpress.org/Function_Reference/get_post_meta">get_post_meta($post_id, $key, $single)</a></em>. Here is an example for the difficulty level of your tutorial:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php if ( get_post_meta($post-&gt;ID, 'difficulty', true) ) : ?&gt;
        Difficulty: &lt;?php echo get_post_meta($post-&gt;ID, 'difficulty', true); ?&gt;
&lt;?php endif; ?&gt;
</pre>
<p>But you can make it simpler to your blog&#8217;s user.</p>
<h2>Predefined Custom Fields</h2>
<p>In your theme&#8217;s <em>functions.php</em> file you are able to predefine which are the custom fields you want for your theme. You have different ways to implement this, so I&#8217;ll show here one way of doing it. So open your theme&#8217;s <em>functions.php</em> file and do the following steps.</p>
<h3>Step 1 &#8211; Field Definition</h3>
<p>We start by defining what fields we&#8217;ll have. We can do that by creating a array with the details of each field. Here I&#8217;m going to create two fields, the difficulty level and a screen cast link (using the YouTube video ID).</p>
<pre class="brush: php; title: ; notranslate">
    $theme_metaboxes = array(
       &quot;difficulty&quot; =&gt; array (
            &quot;name&quot;      =&gt; &quot;difficulty&quot;,
            &quot;default&quot;   =&gt; &quot;3&quot;,
            &quot;label&quot;     =&gt; __('Tutorial Difficulty Level', 'mytheme'),
            &quot;type&quot;      =&gt; &quot;text&quot;,
            &quot;desc&quot;      =&gt; __('Enter the difficulty level here. Use only integer numbers from 0 (zero) to 5 (five).', 'mytheme')
        ),
       &quot;screencast&quot; =&gt; array (
            &quot;name&quot;      =&gt; &quot;screencast&quot;,
            &quot;default&quot;   =&gt; &quot;&quot;,
            &quot;label&quot;     =&gt; __('YouTube Screencast', 'mytheme'),
            &quot;type&quot;      =&gt; &quot;text&quot;,
            &quot;desc&quot;      =&gt; __('Enter the YouTube ID here. For example: http://www.youtube.com/watch?v=SuNprTu5Y5c, use only the &quot;SuNprTu5Y5c&quot; value. Use the original studio trailer if possible.', 'mytheme')
        )
    );
</pre>
<p>As you can see we defined the following values for each field:</p>
<ul>
<li>name: field name;</li>
<li>default: value that should be used as default;</li>
<li>label: name that is displayed to the user;</li>
<li>type: type of the HTML input field;</li>
<li>desc: description shown after the field entry.</li>
</ul>
<h3>Step 2 &#8211; Add the Fields to the New Post Page</h3>
<p>Now we need to add the necessary HTML to the WordPress New Post page. We&#8217;re going to create two new functions and use a new action hook. Here is the code:</p>
<pre class="brush: php; title: ; notranslate">
    function custom_fields_box_content() {
            global $post, $theme_metaboxes;
            foreach ($theme_metaboxes as $theme_metabox) {
                    $theme_metaboxvalue = get_post_meta($post-&gt;ID,$theme_metabox[&quot;name&quot;],true);
                    if ($theme_metaboxvalue == &quot;&quot; || !isset($theme_metaboxvalue)) {
                            $theme_metaboxvalue = $theme_metabox['default'];
                    }
                    echo &quot;\t&quot;.'&lt;p&gt;';
                    echo &quot;\t\t&quot;.'&lt;label for=&quot;'.$theme_metabox['name'].'&quot; style=&quot;font-weight:bold; &quot;&gt;'.$theme_metabox['label'].':&lt;/label&gt;'.&quot;\n&quot;;
                    echo &quot;\t\t&quot;.'&lt;input type=&quot;'.$theme_metabox['type'].'&quot; value=&quot;'.$theme_metaboxvalue.'&quot; name=&quot;'.$theme_metabox[&quot;name&quot;].'&quot; id=&quot;'.$theme_metabox['name'].'&quot;/&gt;&lt;br/&gt;'.&quot;\n&quot;;
                    echo &quot;\t\t&quot;.$theme_metabox['desc'].'&lt;/p&gt;'.&quot;\n&quot;;
            }
    }

    function custom_fields_box() {
            if ( function_exists('add_meta_box') ) {
                    add_meta_box('theme-settings',__('Custom Settings', 'mytheme'),'custom_fields_box_content','post','normal','high');
            }
    }

    add_action('admin_menu', 'custom_fields_box');
</pre>
<p>In this code we use our array with fields to create the necessary HTML to be used in our admin area, when we create a new post. The result is this:</p>
<div id="attachment_154" class="wp-caption alignnone" style="width: 310px"><a href="http://oscardias.com/wp-content/uploads/2010/09/custom_settings.jpg"><img class="size-medium wp-image-154" title="Improved Custom Fields" src="http://oscardias.com/wp-content/uploads/2010/09/custom_settings-300x57.jpg" alt="Improved Custom Fields" width="300" height="57" /></a><p class="wp-caption-text">Improved Custom Fields</p></div>
<p>Much more user friendly, don&#8217;t you think?</p>
<h3>Step 3 &#8211; Using the Values</h3>
<p>The last part is the actual value usage. We need another action hook to add/update/delete our values. So we&#8217;ll create another function like this:</p>
<pre class="brush: php; title: ; notranslate">
    function custom_fields_insert($pID) {
        global $theme_metaboxes;
        foreach ($theme_metaboxes as $theme_metabox) {
            $var = $theme_metabox[&quot;name&quot;];
            if (isset($_POST[$var])) {
                if( get_post_meta( $pID, $theme_metabox[&quot;name&quot;] ) == &quot;&quot; )
                    add_post_meta($pID, $theme_metabox[&quot;name&quot;], $_POST[$var], true );
                elseif($_POST[$var] != get_post_meta($pID, $theme_metabox[&quot;name&quot;], true))
                    update_post_meta($pID, $theme_metabox[&quot;name&quot;], $_POST[$var]);
                elseif($_POST[$var] == &quot;&quot;)
                    delete_post_meta($pID, $theme_metabox[&quot;name&quot;], get_post_meta($pID, $theme_metabox[&quot;name&quot;], true));
            }
        }
    }

    add_action('wp_insert_post', 'custom_fields_insert');
</pre>
<p>As you can see we use the WordPress functions to add, update and delete the values according to the fields we&#8217;ve created.</p>
<p>In order to use these fields, you can do the same as we did for the standard WordPress custom fields. You can create a new function for that as well. For example, in our screen cast example we could create a function that would show the video only if the user set the value:</p>
<pre class="brush: php; title: ; notranslate">
function screen_cast($id) {
    if ($id) {
        echo '&lt;div class=&quot;youtube&quot;&gt;'.
             '&lt;object width=&quot;560&quot; height=&quot;340&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/'.$id.
             '?fs=1&amp;amp;hl=pt_BR&quot;&gt;&lt;/param&gt;'.
             '&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;'.
             '&lt;embed src=&quot;http://www.youtube.com/v/'.$id.'?fs=1&amp;amp;hl=pt_BR&quot; type=&quot;application/x-shockwave-flash&quot; '.
             'allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;560&quot; height=&quot;340&quot;&gt;&lt;/embed&gt;&lt;/object&gt;'.
             '&lt;/div&gt;';
    }
}
</pre>
<p>With this function we can add a simple function call to our <em>single.php</em> template:</p>
<pre class="brush: php; title: ; notranslate">
        &lt;?php screen_cast(get_post_meta($post-&gt;ID, 'screencast', true)); ?&gt;
</pre>
<p>And that&#8217;s all we need to use custom fields!</p>
<h1>Custom Taxonomies</h1>
<p>The last thing I&#8217;m going to show is the custom taxonomies feature added in WordPress 3.0. This is a powerful feature and is really simple to be used. They work just like post tags so you&#8217;re able to use as much values as you want. All you need is a new function and a new action hook in your <em>functions.php</em> file. In the next example I&#8217;m adding the custom taxonomy for a list of actors. The necessary code is:</p>
<pre class="brush: php; title: ; notranslate">
    function create_custom_taxonomies() {
        register_taxonomy('actor', 'post', array(
            'hierarchical' =&gt; false, 'label' =&gt; __('Actor(s)', 'mytheme'),
            'query_var' =&gt; true, 'rewrite' =&gt; true));
    }
    add_action('init', 'create_custom_taxonomies', 0);
</pre>
<p>And that&#8217;s it. It&#8217;s really simple. This is the result:</p>
<div id="attachment_156" class="wp-caption alignnone" style="width: 292px"><a href="http://oscardias.com/wp-content/uploads/2010/09/custom_taxonomy.jpg"><img class="size-full wp-image-156" title="Custom Taxonomy" src="http://oscardias.com/wp-content/uploads/2010/09/custom_taxonomy.jpg" alt="Custom Taxonomy" width="282" height="115" /></a><p class="wp-caption-text">Custom Taxonomy</p></div>
<p>In order to show the values in your <em>single.php</em> template, this is what you need:</p>
<pre class="brush: php; title: ; notranslate">
                &lt;?php echo get_the_term_list($post-&gt;ID, 'actor', __('&lt;p&gt;Actor(s): ', 'mytheme'), ', ', '&lt;/p&gt;'); ?&gt;
</pre>
<h1>Conclusion</h1>
<p>In this article I showed how to use Custom Fields and Custom Taxonomies. These two &#8220;features&#8221; let you customize your blog posts and make them unique. Besides, they help you improve WordPress usability by separating information in different fields.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=xA7N_af6Lw4:1qU-bk4UWlk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=xA7N_af6Lw4:1qU-bk4UWlk:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=xA7N_af6Lw4:1qU-bk4UWlk:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=xA7N_af6Lw4:1qU-bk4UWlk:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/development/php/wordpress/adding-custom-information-to-wordpress-posts/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PHP Class: First Person View</title>
		<link>http://oscardias.com/development/php/php-class-first-person-view/</link>
		<comments>http://oscardias.com/development/php/php-class-first-person-view/#comments</comments>
		<pubDate>Sat, 21 Aug 2010 18:30:02 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[first person view]]></category>
		<category><![CDATA[street view]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=119</guid>
		<description><![CDATA[This article is about a small PHP Class that I wrote this week. The idea was to create a first person website for a virtual tour or a street view functionality. So I created the First Person View Class which allows you to move in four directions with four different angles through a map matrix loaded with images.]]></description>
			<content:encoded><![CDATA[<p><em>This article is about a small PHP Class that I wrote this week. The idea was to create a first person website for a virtual tour or a street view functionality. So I created the First Person View Class which allows you to move in four directions with four different angles through a map matrix loaded with images.</em><br />
<span id="more-119"></span></p>
<p>The public methods provided by this class are:</p>
<ul>
<li>firstPersonView($map, $curX = 0, $curY = 0, $curAng = 0, $path = &#8220;&#8221;) - constructor, needs at least the map matrix with the images (there&#8217;s an example in the end of the post). You should also provide the X, Y position and the angle (0, 90, 180, 270). The last parameter is the path to the image files.</li>
<li>checkForward() and moveForward() &#8211; check if it&#8217;s possible to move forward and the actual move method.</li>
<li>checkBack() and moveBack() &#8211; same thing, but moving backwards.</li>
<li>checkRight() and moveRight() &#8211; same thing, but moving right.</li>
<li>checkLeft() and moveLeft() &#8211; same thing, but moving left.</li>
<li>checkTurnRight() and turnRight() &#8211; same thing, but turning right &#8211; changes the angle.</li>
<li>checkTurnLeft() and turnLeft() &#8211; same thing, but turning left &#8211; changes the angle.</li>
</ul>
<p class="downloadnote">Download the class with the example: <a href="http://oscardias.com/wp-content/uploads/2010/08/fpv.zip">fpv.zip</a></p>
<h2>Example</h2>
<p>To instantiate the class you need to provide a matrix variable with coordinates and angles, like this:</p>
<pre class="brush: php; title: ; notranslate">
$map[X][Y][Angle] = &quot;image&quot;;
</pre>
<p>So, an example with 4 positions would be:</p>
<pre class="brush: php; title: ; notranslate">
$map[0][1][0] = &quot;1-0.jpg&quot;;
$map[0][1][90] = &quot;1-90.jpg&quot;;
$map[0][1][180] = &quot;1-180.jpg&quot;;
$map[0][1][270] = &quot;1-270.jpg&quot;;
$map[1][1][0] = &quot;2-0.jpg&quot;;
$map[1][1][90] = &quot;2-90.jpg&quot;;
$map[1][1][180] = &quot;2-180.jpg&quot;;
$map[1][1][270] = &quot;2-270.jpg&quot;;
$map[1][0][0] = &quot;3-0.jpg&quot;;
$map[1][0][90] = &quot;3-90.jpg&quot;;
$map[1][0][180] = &quot;3-180.jpg&quot;;
$map[1][0][270] = &quot;3-270.jpg&quot;;
$map[1][2][0] = &quot;4-0.jpg&quot;;
$map[1][2][90] = &quot;4-90.jpg&quot;;
$map[1][2][180] = &quot;4-180.jpg&quot;;
$map[1][2][270] = &quot;4-270.jpg&quot;;
</pre>
<p>We can put the coordinates inside a table to have a graphical description of what this code is doing:</p>
<table border="1">
<tbody>
<tr>
<td>2</td>
<td>X</td>
<td>4-0.jpg<br />
4-90.jpg<br />
4-180.jpg<br />
4-270.jpg</td>
</tr>
<tr>
<td>1</td>
<td>1-0.jpg<br />
1-90.jpg<br />
1-180.jpg<br />
1-270.jpg</td>
<td>2-0.jpg<br />
2-90.jpg<br />
2-180.jpg<br />
2-270.jpg</td>
</tr>
<tr>
<td>0</td>
<td>X</td>
<td>3-0.jpg<br />
3-90.jpg<br />
3-180.jpg<br />
3-270.jpg</td>
</tr>
<tr>
<td></td>
<td>0</td>
<td>1</td>
</tr>
</tbody>
</table>
<p>You can see that we have only 4 positions in this example with 16 images, representing each angle of each position. You still need to create an HTML where you will have a form or some links with query strings where you can execute the class methods. Here is the HTML file that comes in the example:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

require_once('fpv.class.php');

// MAP MATRIX
$map[0][1][0] = &quot;1-0.jpg&quot;;
$map[0][1][90] = &quot;1-90.jpg&quot;;
$map[0][1][180] = &quot;1-180.jpg&quot;;
$map[0][1][270] = &quot;1-270.jpg&quot;;
$map[1][1][0] = &quot;2-0.jpg&quot;;
$map[1][1][90] = &quot;2-90.jpg&quot;;
$map[1][1][180] = &quot;2-180.jpg&quot;;
$map[1][1][270] = &quot;2-270.jpg&quot;;
$map[1][0][0] = &quot;3-0.jpg&quot;;
$map[1][0][90] = &quot;3-90.jpg&quot;;
$map[1][0][180] = &quot;3-180.jpg&quot;;
$map[1][0][270] = &quot;3-270.jpg&quot;;
$map[1][2][0] = &quot;4-0.jpg&quot;;
$map[1][2][90] = &quot;4-90.jpg&quot;;
$map[1][2][180] = &quot;4-180.jpg&quot;;
$map[1][2][270] = &quot;4-270.jpg&quot;;

if (isset($_POST[&quot;current_angle&quot;])) {
    $fpv = new firstPersonView($map, $_POST[&quot;current_x&quot;], $_POST[&quot;current_y&quot;], $_POST[&quot;current_angle&quot;], &quot;images&quot;);
} else {
    $fpv = new firstPersonView($map, 0, 1, 0, &quot;images&quot;);
}

if($_POST['go-forward']) {
    $fpv-&gt;goForward();
} else if($_POST['go-back']) {
    $fpv-&gt;goBack();
} else if($_POST['go-left']) {
    $fpv-&gt;goLeft();
} else if($_POST['go-right']) {
    $fpv-&gt;goRight();
} else if($_POST['turn-right']) {
    $fpv-&gt;turnRight();
} else if($_POST['turn-left']) {
    $fpv-&gt;turnLeft();
}

?&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;First Person View Class - Example&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;p&gt;Please go to
            &lt;a href=&quot;http://oscardias.com/php/php-class-first-person-view/&quot;&gt;http://oscardias.com/php/php-class-first-person-view/&lt;/a&gt;
            if ou need more info.
        &lt;/p&gt;
        &lt;form name=&quot;movements&quot; action=&quot;example.php&quot; method=&quot;post&quot;&gt;
            &lt;input type=&quot;submit&quot; name=&quot;turn-left&quot; value=&quot;Turn Left&quot; &lt;?php echo ($fpv-&gt;checkTurnLeft())?&quot;&quot;:&quot;disabled&quot;; ?&gt;/&gt;
            &lt;input type=&quot;submit&quot; name=&quot;go-left&quot; value=&quot;Move Left&quot; &lt;?php echo ($fpv-&gt;checkLeft())?&quot;&quot;:&quot;disabled&quot;; ?&gt;/&gt;
            &lt;input type=&quot;submit&quot; name=&quot;go-forward&quot; value=&quot;Move Forward&quot; &lt;?php echo ($fpv-&gt;checkForward())?&quot;&quot;:&quot;disabled&quot;; ?&gt;/&gt;
            &lt;input type=&quot;submit&quot; name=&quot;go-back&quot; value=&quot;Move Back&quot; &lt;?php echo ($fpv-&gt;checkBack())?&quot;&quot;:&quot;disabled&quot;; ?&gt;/&gt;
            &lt;input type=&quot;submit&quot; name=&quot;go-right&quot; value=&quot;Move Right&quot; &lt;?php echo ($fpv-&gt;checkRight())?&quot;&quot;:&quot;disabled&quot;; ?&gt;/&gt;
            &lt;input type=&quot;submit&quot; name=&quot;turn-right&quot; value=&quot;Turn Right&quot; &lt;?php echo ($fpv-&gt;checkTurnRight())?&quot;&quot;:&quot;disabled&quot;; ?&gt;/&gt;
            &lt;!-- BEGIN IMPORTANT HIDDEN INFO --&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;current_x&quot; value=&quot;&lt;?php echo $fpv-&gt;currentX; ?&gt;&quot; /&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;current_y&quot; value=&quot;&lt;?php echo $fpv-&gt;currentY; ?&gt;&quot; /&gt;
            &lt;input type=&quot;hidden&quot; name=&quot;current_angle&quot; value=&quot;&lt;?php echo $fpv-&gt;currentAngle; ?&gt;&quot; /&gt;
            &lt;!-- END IMPORTANT HIDDEN INFO --&gt;
        &lt;/form&gt;
        &lt;img id=&quot;view&quot; src=&quot;&lt;?php $fpv-&gt;currentView() ?&gt;&quot; /&gt;
    &lt;/body&gt;
&lt;/html&gt;
</pre>
<p class="updatenote">Now the demo is online. You can check it in: <a href="http://oscardias.com/other/fpv/example.php">http://oscardias.com/other/fpv/example.php</a></p>
<h2>Notes</h2>
<p>This is the first version of the class. I did&#8217;n have time to detail it too much, but if you&#8217;re interested in it, leave your comment. I&#8217;ll dedicate more time to it <img src='http://oscardias.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p class="updatenote">This class has been approved in the <a href="http://www.phpclasses.org/">PHPClasses.org</a> website with a notable package notification. The direct link to the package is <a href="http://www.phpclasses.org/package/6460.html">http://www.phpclasses.org/package/6460.html</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=s3r0paWzm5Q:9q0jRTgbb64:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=s3r0paWzm5Q:9q0jRTgbb64:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=s3r0paWzm5Q:9q0jRTgbb64:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=s3r0paWzm5Q:9q0jRTgbb64:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/development/php/php-class-first-person-view/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Tip: How to Use the Official Twitter Tweet Button</title>
		<link>http://oscardias.com/other/tip-how-to-use-the-official-twitter-tweet-button/</link>
		<comments>http://oscardias.com/other/tip-how-to-use-the-official-twitter-tweet-button/#comments</comments>
		<pubDate>Sat, 14 Aug 2010 19:38:55 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[share]]></category>
		<category><![CDATA[social media]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=113</guid>
		<description><![CDATA[Recently I showed here how to create sharing buttons for different social media. At the time there was no official Twitter code for this purpose. But this week Twitter released it's own Tweet Button. So I'll quickly show how to use it.]]></description>
			<content:encoded><![CDATA[<p><em>Recently I showed here how to create sharing buttons for different social media. At the time there was no official Twitter code for this purpose. But this week Twitter released it&#8217;s own Tweet Button. So I&#8217;ll quickly show how to use it.</em><br />
<span id="more-113"></span></p>
<h1>Introduction</h1>
<p>Recently I wrote the post <a title="Permanent Link to Adding Share Buttons for Twitter, Facebook, Buzz and Others" href="http://oscardias.com/other/adding-share-buttons-for-twitter-facebook-buzz-and-others/" rel="bookmark">Adding Share Buttons for Twitter, Facebook, Buzz and Others</a>, where I explained how to create sharing buttons for some social media sites. But when I wrote that post, there was no official solution provided by Twitter itself. Now Twitter has made available their own code for this. So let&#8217;s see how it works.</p>
<h1>Code</h1>
<p>It&#8217;s quite simple and can be obtained in the following address <a href="http://twitter.com/goodies/tweetbutton">Twitter / Tweet Button</a>. Let me make it simpler and show the necessary code:</p>
<pre class="brush: php; title: ; notranslate">
&lt;a href=&quot;http://twitter.com/share&quot; class=&quot;twitter-share-button&quot; data-url=&quot;http://yourdomain.com&quot; data-text=&quot;Share Text&quot; data-count=&quot;vertical&quot; data-via=&quot;oscardias&quot;&gt;Tweet&lt;/a&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://platform.twitter.com/widgets.js&quot;&gt;&lt;/script&gt;
</pre>
<p>As you can see we can customize the following information:</p>
<ul>
<li>data-url: link to be shared. If you delete this property, the page link will be shared by default. Twitter will also use their own URL shortener, so you don&#8217;t have to worry about that.</li>
<li>data-text: text to be shared. If you delete this property, the page title will be shared by default.</li>
<li>data-count: button style. I can contain the values: vertical, horizontal or none. The &#8220;vertical&#8221; value will show the counter above the button. The &#8220;horizontal&#8221; value will show the counter next to the button. And the value &#8220;none&#8221; will show only the button, without the counter.</li>
<li>data-via: Twitter&#8217;s username to be reshared.</li>
</ul>
<p>You can also change the button text by replacing the text inside the link tags</p>
<h1>Conclusion</h1>
<p>This is all we need to add the official Twitter button. A lot of people is already changing Tweetmeme button for Twitter&#8217;s one, but the decision is up to you. Thanks for visiting.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=znysw0FO_qk:HjLRghzQtio:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=znysw0FO_qk:HjLRghzQtio:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=znysw0FO_qk:HjLRghzQtio:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=znysw0FO_qk:HjLRghzQtio:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/other/tip-how-to-use-the-official-twitter-tweet-button/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a WordPress Theme (Part 6): Footer</title>
		<link>http://oscardias.com/development/php/wordpress/creating-a-wordpress-theme-part-6-footer/</link>
		<comments>http://oscardias.com/development/php/wordpress/creating-a-wordpress-theme-part-6-footer/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 21:29:12 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=95</guid>
		<description><![CDATA[This is the last part of the series. We've already seen the design creation, an introduction about the WordPress platform and the coding and styling of the entire theme except the footer.  So, in this last post, we're going to do the footer and, to finish our blog, let's also see some widgets. The footer is pretty simple and we're going to add some additional styles that we've been using during the series.]]></description>
			<content:encoded><![CDATA[<p><em>This is the last part of the series. We&#8217;ve already seen the design creation, an introduction about the WordPress platform and the coding and styling of the entire theme except the footer.  So, in this last post, we&#8217;re going to do the footer and, to finish our blog, let&#8217;s also see some plugins. The footer is pretty simple and we&#8217;re going to add some additional styles that we&#8217;ve been using during the series.</em></p>
<p><em>If you want to catch up with the current status of our theme, please download it <a href="http://oscardias.com/br/wp-content/uploads/2010/06/mytheme1.zip">here</a>.</em></p>
<p><span id="more-95"></span></p>
<h1>Introduction</h1>
<p>This is the sixth and last part of my WordPress theme creation series. Here is a list of all articles from the series:</p>
<p class="previousnote"><a href="http://oscardias.com/photoshop/creating-a-wordpress-theme-part-1-photoshop/">Creating a WordPress Theme (Part 1): Photoshop</a><br />
<a href="http://oscardias.com/wordpress/creating-a-wordpress-theme-part-2-introduction/">Creating a WordPress Theme (Part 2): Introduction</a><br />
<a href="http://oscardias.com/wordpress/creating-a-wordpress-theme-part-3-header/">Creating a WordPress Theme (Part 3): Header</a><br />
<a href="http://oscardias.com/wordpress/creating-a-wordpress-theme-part-4-home-page/">Creating a WordPress Theme (Part 4): Home Page</a><br />
<a href="http://oscardias.com/wordpress/creating-a-wordpress-theme-part-5-pages-and-posts/">Creating a WordPress Theme (Part 5): Pages and Posts</a></p>
<p>Today I&#8217;m only going to finish our footer and create some additional styles. Later I&#8217;m also going to describe some plugins I use.</p>
<h1>Footer</h1>
<p>Currently this is how our footer looks:</p>
<div id="attachment_106" class="wp-caption alignnone" style="width: 310px"><a href="http://oscardias.com/wp-content/uploads/2010/07/old_footer.jpg"><img class="size-medium wp-image-106" title="Our footer before our changes" src="http://oscardias.com/wp-content/uploads/2010/07/old_footer-300x26.jpg" alt="Our footer before our changes" width="300" height="26" /></a><p class="wp-caption-text">Our footer before our changes</p></div>
<p>So, in order to change this, let&#8217;s open the <em>footer.php</em> file.</p>
<ol>
<li>Update the package information: we&#8217;ve been using @subpackage MyTheme_Theme.</li>
<li>Now replace all occurrences of &#8216;kubrick&#8217; with &#8216;mytheme&#8217;.</li>
<li>Remove the &lt;hr&gt; on the beginning.</li>
<li>Let&#8217;s add a &lt;div class=&#8221;container_12&#8243;&gt; after our &lt;div id=&#8221;footer&#8221;&gt;.</li>
<li>Inside the previous created DIV we&#8217;re going to add two DIV&#8217;s. First, let&#8217;s add the links to our blog floated left. Add the following code:
<pre class="brush: php; title: ; notranslate">
        &lt;div class=&quot;floatleft&quot;&gt;
            &lt;ul&gt;
                &lt;li class=&quot;page_item first_page_item &lt;?php if ( is_home() ) { ?&gt;current_page_item&lt;?php } ?&gt;&quot;&gt;&lt;a href=&quot;&lt;?php echo get_settings('home'); ?&gt;/&quot; title=&quot;&lt;?php _e('Home', 'oscardias'); ?&gt;&quot;&gt;&lt;?php _e('Home', 'oscardias'); ?&gt;&lt;/a&gt;&lt;/li&gt;
                &lt;?php wp_list_pages('sort_column=post_title&amp;title_li=');?&gt;

            &lt;/ul&gt;
        &lt;/div&gt;
</pre>
</li>
<li>Next, we&#8217;re going to add some info about our blog and theme floated and aligned  right. Add the following code:
<pre class="brush: php; title: ; notranslate">
        &lt;div class=&quot;floatright alignright&quot;&gt;
            &amp;copy; 2010 &lt;a href=&quot;&lt;?php echo get_option('home'); ?&gt;/&quot;&gt;Oscar Dias&lt;/a&gt;
            &lt;br /&gt;&lt;?php printf(__('%1$s is powered by %2$s', 'oscardias'), get_bloginfo('name'),'&lt;a href=&quot;http://wordpress.org/&quot;&gt;WordPress&lt;/a&gt;'); ?&gt;

            &lt;br /&gt;&lt;?php printf(__('%1$s and %2$s', 'oscardias'), '&lt;a href=&quot;' . get_bloginfo('rss2_url') . '&quot;&gt;' . __('Entries (RSS)', 'oscardias') . '&lt;/a&gt;', '&lt;a href=&quot;' . get_bloginfo('comments_rss2_url') . '&quot;&gt;' . __('Comments (RSS)', 'oscardias') . '&lt;/a&gt;'); ?&gt;

        &lt;/div&gt;
</pre>
</li>
<li>Finish it by adding a &lt;div class=&#8221;clear&#8221;&gt;&lt;/div&gt; after you close the &lt;div class=&#8221;container_12&#8243;&gt;.</li>
</ol>
<p>Really easy, Here is the final code:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * @package WordPress
 * @subpackage MyTheme_Theme
 */
?&gt;

&lt;div id=&quot;footer&quot; role=&quot;contentinfo&quot;&gt;
    &lt;div class=&quot;container_12&quot;&gt;
        &lt;div class=&quot;floatleft&quot;&gt;
            &lt;ul&gt;
                &lt;li class=&quot;page_item first_page_item &lt;?php if ( is_home() ) { ?&gt;current_page_item&lt;?php } ?&gt;&quot;&gt;&lt;a href=&quot;&lt;?php echo get_settings('home'); ?&gt;/&quot; title=&quot;&lt;?php _e('Home', 'oscardias'); ?&gt;&quot;&gt;&lt;?php _e('Home', 'oscardias'); ?&gt;&lt;/a&gt;&lt;/li&gt;
                &lt;?php wp_list_pages('sort_column=post_title&amp;title_li=');?&gt;

            &lt;/ul&gt;
        &lt;/div&gt;
        &lt;div class=&quot;floatright alignright&quot;&gt;
            &amp;copy; 2010 &lt;a href=&quot;&lt;?php echo get_option('home'); ?&gt;/&quot;&gt;Oscar Dias&lt;/a&gt;
            &lt;br /&gt;&lt;?php printf(__('%1$s is powered by %2$s', 'oscardias'), get_bloginfo('name'),'&lt;a href=&quot;http://wordpress.org/&quot;&gt;WordPress&lt;/a&gt;'); ?&gt;

            &lt;br /&gt;&lt;?php printf(__('%1$s and %2$s', 'oscardias'), '&lt;a href=&quot;' . get_bloginfo('rss2_url') . '&quot;&gt;' . __('Entries (RSS)', 'oscardias') . '&lt;/a&gt;', '&lt;a href=&quot;' . get_bloginfo('comments_rss2_url') . '&quot;&gt;' . __('Comments (RSS)', 'oscardias') . '&lt;/a&gt;'); ?&gt;

        &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
		&lt;?php wp_footer(); ?&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>This is the result:</p>
<div id="attachment_107" class="wp-caption alignnone" style="width: 310px"><a href="http://oscardias.com/wp-content/uploads/2010/07/footer_nostyles.jpg"><img class="size-medium wp-image-107" title="Footer without the necessary styles" src="http://oscardias.com/wp-content/uploads/2010/07/footer_nostyles-300x28.jpg" alt="Footer without the necessary styles" width="300" height="28" /></a><p class="wp-caption-text">Footer without the necessary styles</p></div>
<p>We still need to create our last styles.</p>
<h1>Styles</h1>
<p>Let&#8217;s open our <em>styles.css</em> file.</p>
<ol>
<li>First of all, <a title="Footer background" href="http://oscardias.com/wp-content/uploads/2010/07/footer.jpg">download this image</a>. We&#8217;re going to use it as our background image.</li>
<li>Now let&#8217;s style the footer DIV.
<pre class="brush: css; title: ; notranslate">
#footer {
    background: #fff url('images/footer.jpg') repeat-x top;
    margin: 0 auto;
    padding-top:100px;
    padding-bottom:20px;
}
</pre>
</li>
<li>Let&#8217;s continue and create the styles for the footer lists (UL and LI).
<pre class="brush: css; title: ; notranslate">
#footer ul {
    list-style: none;
    margin:0;
    padding:0;
}
#footer ul li {
    float:left;
    margin:5px 0 5px 5px;
    padding-right:5px;
    border-right: 1px solid #000;
}
</pre>
</li>
<li>We&#8217;re almost there. But we still need to create the styles to align everything. So let&#8217;s create different align classes.
<pre class="brush: css; title: ; notranslate">
.floatleft {
    float:left;
    margin-left: 10px;
}
.floatright {
    float:right;
    margin-right: 10px;
}
.alignleft {
    text-align: left;
}
.alignright {
    text-align: right;
}
.center {
    text-align: center;
}
</pre>
</li>
<li>Now let&#8217;s add some additional classes. We&#8217;re going to style the shadows and the images.
<pre class="brush: css; title: ; notranslate">
.box-shadow {
    box-shadow: 3px 3px 3px #000;
    -moz-box-shadow: 3px 3px 3px #000; /* for Firefox 3.5+ */
    -webkit-box-shadow: 3px 3px 3px #000; /* for Safari and Chrome */
}
.text-shadow {
    text-shadow: #000 2px 2px 2px;
}
img.aligncenter, img.center {
    display: block;
    margin-left: auto;
    margin-right: auto;
}
.frame {
    padding:5px;
    background: #d2d2d2;
    border: 2px solid #808080;
}</pre>
</li>
</ol>
<p>And that&#8217;s it. We&#8217;ve finished the development of our theme. I didn&#8217;t covered all files, but the remaining ones should follow the same ideas we&#8217;ve been using during these series.</p>
<p>Now let me show what plugins I&#8217;m using.</p>
<h1>Plugins</h1>
<p>Here is a quick list about the plugins I&#8217;m using with the explanation.</p>
<h2>AddToAny: Share/Bookmark/Email Button</h2>
<p>Plugin for sharing/bookmarking. Really useful and complete. It only takes one button to enable your readers to share over lot&#8217;s of different social medias.</p>
<h2>Akismet</h2>
<p>This one comes with the default installation of WordPress. It will filter comments made in your website and check whether their spam or not automatically. This way you don&#8217;t need to check each and every comment made in your blog.</p>
<h2>All in One SEO Pack</h2>
<p>Another great plugin that improves your blogs SEO capabilities.</p>
<h2>FD Feedburner Plugin</h2>
<p>If you use Feedburner, this one is mandatory. It will redirect all feeds to your Feedburner feed.</p>
<h2>Google Analytics for WordPress</h2>
<p>Also, if you use Google Analytics, this plugin will add analytics code automatically for you.</p>
<h2>Google XML Sitemaps</h2>
<p>This plugin will generate sitemaps automatically for your website. Sitemaps are used by search engines to index your blog, so it&#8217;s quite important.</p>
<h2>RatenTweet</h2>
<p>This one adds another way to share your posts in Twitter using a quick rating system.</p>
<h2>SyntaxHighlighter Evolved</h2>
<p>Plugin for syntax highlighting. It will take your code entries and make them look pretty.</p>
<h2>TweetMeme Retweet Button</h2>
<p>Another Twitter sharing service. It&#8217;s used all over the web.</p>
<h1>Conclusion</h1>
<p>So we&#8217;ve came to the end of our series about WordPress themes. I&#8217;ll write about WordPress again, but not in this series. If you have any comments or if you want to see something specific here, leave your message and I&#8217;ll answer as soon as possible <img src='http://oscardias.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p class="downloadnote">Download the last version of our theme <a title="MyTheme" href="http://oscardias.com/wp-content/uploads/2010/07/mytheme.zip">here</a> (82 Kb).</p>
<p class="previousnote"><strong>Other Posts from the Series</strong><br />
<a href="http://oscardias.com/photoshop/creating-a-wordpress-theme-part-1-photoshop/">Creating a WordPress Theme (Part 1): Photoshop</a><br />
<a href="http://oscardias.com/wordpress/creating-a-wordpress-theme-part-2-introduction/">Creating a WordPress Theme (Part 2): Introduction</a><br />
<a href="http://oscardias.com/wordpress/creating-a-wordpress-theme-part-3-header/">Creating a WordPress Theme (Part 3): Header</a><br />
<a href="http://oscardias.com/wordpress/creating-a-wordpress-theme-part-4-home-page/">Creating a WordPress Theme (Part 4): Home Page</a><br />
<a href="http://oscardias.com/wordpress/creating-a-wordpress-theme-part-5-pages-and-posts/">Creating a WordPress Theme (Part 5): Pages and Posts</a></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=qRC2sWypN9w:nqxPWQOibf0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=qRC2sWypN9w:nqxPWQOibf0:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=qRC2sWypN9w:nqxPWQOibf0:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=qRC2sWypN9w:nqxPWQOibf0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/development/php/wordpress/creating-a-wordpress-theme-part-6-footer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Adding Share Buttons for Twitter, Facebook, Buzz and Others</title>
		<link>http://oscardias.com/other/adding-share-buttons-for-twitter-facebook-buzz-and-others/</link>
		<comments>http://oscardias.com/other/adding-share-buttons-for-twitter-facebook-buzz-and-others/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 03:39:25 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[buzz]]></category>
		<category><![CDATA[digg]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[reddit]]></category>
		<category><![CDATA[share]]></category>
		<category><![CDATA[social media]]></category>
		<category><![CDATA[stumbleupon]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=98</guid>
		<description><![CDATA[Today I was working on a project and I had to search for some share functionalities. I wanted to get the original code from the original social media websites and not a third party hack or something like that. So I found codes for Twitter, Facebook, Google Buzz, StumbleUpon, Reddit and Digg. The only one that's not from the original website is Twitter, so I used Tweetmeme instead.]]></description>
			<content:encoded><![CDATA[<p><em>Today I was working on a project and I had to search for some share functionalities. I wanted to get the original code from the original social media websites and not a third party hack or something like that. So I found codes for <a href="http://twitter.com/">Twitter</a>, <a href="http://www.facebook.com/">Facebook</a>, <a href="http://www.google.com/buzz/">Google Buzz</a>, <a href="http://www.stumbleupon.com/">StumbleUpon</a>, <a href="http://www.reddit.com/">Reddit</a> and <a href="http://digg.com/">Digg</a>. The only one that&#8217;s not from the original website is Twitter, so I used <a href="http://tweetmeme.com/">Tweetmeme</a> instead.</em><br />
<span id="more-98"></span></p>
<h1>Introduction</h1>
<p>I&#8217;m sure you have already seen some of the icons displayed in this post. And you probably use some of these services. But do you know how to add a share link to your website the proper way? That&#8217;s what I&#8217;m going to show here. I used the official references to find the code examples I&#8217;m going to show here.</p>
<h2>Twitter</h2>
<p>Twitter is one of the most famous social media websites today. Unfortunately I didn&#8217;t found the official &#8220;tweet&#8221; button with tweet count. But, in this case, we have Tweetmeme, which is widely used.</p>
<p><strong>Reference:</strong> <a href="http://help.tweetmeme.com/2009/04/06/tweetmeme-button/">http://help.tweetmeme.com/2009/04/06/tweetmeme-button/</a></p>
<p>Here is a simple example with the big size button. You can see that you can customize the source and the URL. You should set a short URL or use the <em>tweetmeme_service</em> parameter. You can also use the compact button adding the code &#8220;<em>tweetmeme_style = &#8216;compact&#8217;;</em>&#8220;.</p>
<pre class="brush: xml; title: ; notranslate">
 &lt;script type=&quot;text/javascript&quot;&gt;
    tweetmeme_source = 'username';
    tweetmeme_url = 'http://yourdomain.com';
&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://tweetmeme.com/i/scripts/button.js&quot;&gt;&lt;/script&gt;
</pre>
<p>An additional feature is the ability to change the tweet text. By default it will use the page title, but if you want to change it, you have to add the following:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;meta name=&quot;tweetmeme-title&quot; content=&quot;Different Text&quot; /&gt;
</pre>
<h2>Facebook</h2>
<p>Facebook is also very famous. And has great developer tools. So it&#8217;s really easy to create a share button for it. You can customize it and get the code in the following website:</p>
<p><strong>Reference:</strong> <a href="http://www.facebook.com/share/">http://www.facebook.com/share/</a></p>
<p>Here is an example for the box size. It will use the page title and the page URL as the values to be posted. In this case we don&#8217;t need to limit the size to 140 chars.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a name=&quot;fb_share&quot; type=&quot;box_count&quot; href=&quot;http://www.facebook.com/sharer.php&quot;&gt;&lt;/a&gt;
&lt;script src=&quot;http://static.ak.fbcdn.net/connect.php/js/FB.Share&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
</pre>
<p>If you want, you can use &#8216;<em>type=&#8221;button_count</em>&#8220;&#8216; for the small button. You can also customize the title and URL to be shared by changing the HREF value like this: <em>http://www.facebook.com/sharer.php?u=url&amp;t=text</em></p>
<h2>Google Buzz</h2>
<p>Google Buzz is one of the most recent social medias. It was developed by Google as a response to Twitter. It has some nice resources for sharing.</p>
<p><strong>Reference:</strong> <a href="http://code.google.com/apis/buzz/buttons_and_gadgets.html">http://code.google.com/apis/buzz/buttons_and_gadgets.html</a></p>
<p>One of the most customizable resource uses JavaScript together with HTML5 tags. Here is an example using the normal size button.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a href=&quot;http://www.google.com/buzz/post&quot;
    class=&quot;google-buzz-button&quot;
    title=&quot;Google Buzz&quot;
    data-message=&quot;Message Text&quot;
    data-url=&quot;http://yourdomain.com&quot;
    data-locale=&quot;en&quot;
    data-button-style=&quot;normal-count&quot;&gt;&lt;/a&gt;
    &lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/buzz/api/button.js&quot;&gt;&lt;/script&gt;
</pre>
<p>You can use &#8216;<em>data-button-style=&#8221;small-count&#8221;</em>&#8216; for the small button with counter.</p>
<h2>StumbleUpon</h2>
<p>StumbleUpon has one of the best ways to create the button code. All you have to do it check this website:</p>
<p><strong>Reference:</strong> <a href="http://www.stumbleupon.com/buttons/">http://www.stumbleupon.com/buttons/</a></p>
<p>From there you can select the button style and if you want to add it to existing platforms or your own website. The code for the bigger button is this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script src=&quot;http://www.stumbleupon.com/hostedbadge.php?s=5&amp;r=http://yourdomain.com&quot;&gt;&lt;/script&gt;
</pre>
<p>You may remove the &#8216;<em>&amp;r=http://yourdomain.com</em>&#8216; if you want. The JavaScript will get the current page URL in this case.</p>
<h2>Reddit</h2>
<p>Reddit has nice buttons available. With small size, big size and even with the ET <img src='http://oscardias.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><strong>Reference:</strong> <a href="http://www.reddit.com/buttons/">http://www.reddit.com/buttons/</a></p>
<p>In this page you can choose your preferred option and just check the code. It also have great customization options, all done via JavaScript. The basic code for a big button is this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot; src=&quot;http://reddit.com/static/button/button2.js&quot;&gt;&lt;/script&gt;
</pre>
<p>If you change to button1.js, you&#8217;ll have a small button. If you change to button3.js you&#8217;ll have their ET logo. And you can customize it with the following options:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;reddit_url='[URL]'&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;reddit_target='[COMMUNITY]'&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;reddit_title='[TITLE]'&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;reddit_newwindow='1'&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;reddit_bgcolor='[COLOR]'&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;reddit_bordercolor='[COLOR]'&lt;/script&gt;
</pre>
<h2>Digg</h2>
<p>Digg is another social media that has nice buttons. It&#8217;s a little bit different though. It&#8217;s based in one basic code, and the details are customized directly in the A tag.</p>
<p><strong>Reference:</strong> <a href="http://about.digg.com/button">http://about.digg.com/button</a></p>
<p>This is the basic JavaScript code:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
(function() {
var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];
s.type = 'text/javascript';
s.async = true;
s.src = 'http://widgets.digg.com/buttons.js';
s1.parentNode.insertBefore(s, s1);
})();
&lt;/script&gt;
</pre>
<p>In order to place the button, you have to add the following tag where you want:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a class=&quot;DiggThisButton DiggMedium&quot;&gt;&lt;/a&gt;
</pre>
<p>All options should be added to this last tag. For example, to show a small button you can simply change the class to &#8220;<em>DiggThisButton DiggCompact</em>&#8220;. If you want to customize the URL, you can use the following:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a class=&quot;DiggThisButton DiggMedium&quot; href=&quot;http://yourdomain.com&quot;&gt;&lt;/a&gt;
</pre>
<h1>Conclusion</h1>
<p>In this quick post we saw some social media buttons. I chose the ones that have the counter because they provide a instant feedback about your post/page popularity. If you want to implement them, it&#8217;s a good idea to check the references I mentioned.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=_jYQpdo5Hx0:JPfpYzCItDU:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=_jYQpdo5Hx0:JPfpYzCItDU:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=_jYQpdo5Hx0:JPfpYzCItDU:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=_jYQpdo5Hx0:JPfpYzCItDU:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/other/adding-share-buttons-for-twitter-facebook-buzz-and-others/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

