<?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>Sun, 20 Nov 2011 11:36:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</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>Integrating WordPress with CodeIgniter</title>
		<link>http://oscardias.com/codeigniter/integrating-wordpress-with-codeigniter/</link>
		<comments>http://oscardias.com/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=raXGcIJ3cd0: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=raXGcIJ3cd0:cwhY7iEdJB0:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=raXGcIJ3cd0:cwhY7iEdJB0:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=raXGcIJ3cd0:cwhY7iEdJB0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/codeigniter/integrating-wordpress-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Add a Rate Field to WordPress Comments</title>
		<link>http://oscardias.com/wordpress/how-to-add-a-rate-field-to-wordpress-comments/</link>
		<comments>http://oscardias.com/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=3-N1Bu1XFXs: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=3-N1Bu1XFXs:Uwf9DQyqwqw:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=3-N1Bu1XFXs:Uwf9DQyqwqw:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=3-N1Bu1XFXs:Uwf9DQyqwqw:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/wordpress/how-to-add-a-rate-field-to-wordpress-comments/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Adding Custom Information to WordPress Posts</title>
		<link>http://oscardias.com/wordpress/adding-custom-information-to-wordpress-posts/</link>
		<comments>http://oscardias.com/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=hd22xAfnX_w: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=hd22xAfnX_w:1qU-bk4UWlk:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=hd22xAfnX_w:1qU-bk4UWlk:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=hd22xAfnX_w: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/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/php/php-class-first-person-view/</link>
		<comments>http://oscardias.com/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=KwzfgdCTweU: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=KwzfgdCTweU:9q0jRTgbb64:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=KwzfgdCTweU:9q0jRTgbb64:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=KwzfgdCTweU:9q0jRTgbb64:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/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/wordpress/creating-a-wordpress-theme-part-6-footer/</link>
		<comments>http://oscardias.com/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=KqGSr3wLyo4: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=KqGSr3wLyo4:nqxPWQOibf0:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=KqGSr3wLyo4:nqxPWQOibf0:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=KqGSr3wLyo4:nqxPWQOibf0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/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>
		<item>
		<title>Agile Brazil 2010 – Brazilian Conference on Agile Methods</title>
		<link>http://oscardias.com/methodologies/agile-brazil-2010-brazilian-conference-on-agile-methods/</link>
		<comments>http://oscardias.com/methodologies/agile-brazil-2010-brazilian-conference-on-agile-methods/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 02:47:34 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[Methodologies]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[methodologies]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=83</guid>
		<description><![CDATA[Last week took place in Porto Alegre, Brazil, the Brazilian Conference on Agile Methods &#8211; Agile Brazil 2010. The event was a great opportunity to see presentations about different methods and experiences related to the agile community. I was there and I want to write a little bit about what I saw. About the Conference [...]]]></description>
			<content:encoded><![CDATA[<p><em>Last week took place in Porto Alegre, Brazil, the Brazilian Conference on Agile Methods &#8211; </em><a href="http://www.agilebrazil.com/"><em>Agile Brazil 2010</em></a><em>. The event was a great opportunity to see presentations about different methods and experiences related to the agile community. I was there and I want to write a little bit about what I saw.</em></p>
<p><em><span id="more-83"></span></em></p>
<h1>About the Conference</h1>
<p>The conference was a great initiative by the agile community and was a success. The keynotes of the event were presented by some of the well known names of the agile community: Martin Fowler (from ThoughtWorks), Philippe Kruchten (professor of software engineering at the University of British Columbia) and Klaus Wuestefeld (Extreme Programming pioneer in Brazil). There was a total of 820 subscribers and 188 submissions (papers and presentations).</p>
<div id="attachment_93" class="wp-caption alignnone" style="width: 310px"><a href="http://oscardias.com/wp-content/uploads/2010/07/IMG_0324.jpg"><img class="size-medium wp-image-93" title="Main Auditorium" src="http://oscardias.com/wp-content/uploads/2010/07/IMG_0324-300x225.jpg" alt="Main Auditorium" width="300" height="225" /></a><p class="wp-caption-text">Main Auditorium</p></div>
<p>I&#8217;m going to write a little bit about it. I wasn&#8217;t able to be in all presentations at once, of course, so I&#8217;ll just go through some of the presentations I attended.</p>
<h2>Martin Fowler (Keynote)</h2>
<p>Martin Fowler (<a href="http://martinfowler.com/">http://martinfowler.com/</a>) gave three different talks. He started with &#8220;The Essence of Agile&#8221;, in which he pretty much gave an overview about Agile. He have some articles in his website related to this presentation:</p>
<ul>
<li>The New Methodology: <a href="http://martinfowler.com/articles/newMethodology.html">http://martinfowler.com/articles/newMethodology.html</a></li>
<li>Is Design Dead?: <a href="http://martinfowler.com/articles/designDead.html">http://martinfowler.com/articles/designDead.html</a></li>
</ul>
<p>Later on he continued his keynote talking about Technical Debt. He showed us a quadrant to explain it. Links from his website:</p>
<ul>
<li>Technical Debt: <a href="http://www.martinfowler.com/bliki/TechnicalDebt.html">http://www.martinfowler.com/bliki/TechnicalDebt.html</a></li>
<li>Technical Debt Quadrant: <a href="http://www.martinfowler.com/bliki/TechnicalDebtQuadrant.html">http://www.martinfowler.com/bliki/TechnicalDebtQuadrant.html</a></li>
</ul>
<p>In his third talk he spoke about &#8220;Continuous Integration and Delivery&#8221;. Again, here is an article he wrote on the topic:</p>
<ul>
<li>Continuous Integration: <a href="http://martinfowler.com/articles/continuousIntegration.html">http://martinfowler.com/articles/continuousIntegration.html</a></li>
</ul>
<h2>Alisson Vale &#8211; Kanban: Em Busca de um Ritmo Sustentável</h2>
<p>In a free translation into English, it&#8217;s something like &#8220;Kanban: Searching for a Sustainable Rhythm&#8221;. I had already watched a speech from Alisson at the Ágiles 2009 (<a href="http://alissonvale.com/englishblog/post/Kanban-Development-and-the-Paradigm-of-Flow.aspx">&#8220;Kanban Development and the Paradigm of Flow&#8221;</a>) and I found it very interesting. So this year I chose to see his presentation again and it was worth it. As my first internship was at a Production Engineering company, I&#8217;ve always heard about Kanban and it&#8217;s really good to see it applied to software development.</p>
<p>He talked the background of Kanban &#8211; going back to Taiichi Ohno &#8211; and explained the WIP (work in progress) influence over the lead time. As he continued, he went through the core concepts of Kanban and additional techniques like MMF (Minimum Markable Feature) and Swimlanes.</p>
<p>Don&#8217;t forget to check out his blog at <a href="http://alissonvale.com/">http://alissonvale.com/</a>.</p>
<h2>David Hussman &#8211; Products and People over Process and Dogma</h2>
<p>David Hussman is the owner of <a href="http://devjam.com/">DevJam</a>, a company focused on &#8220;Coaching &amp; Developing Agility&#8221;. He won the Gordon Pask Award in 2009 for his contribution to the agile community.</p>
<p>David&#8217;s speech started with comparison between product and process. He asked us to write three words to describe our process and think how these words related to our product. He suggested a few books: <em>The Black Swan</em> (by Nassim Nicholas Taleb), <em>Freakonomics</em> (by Levitt &amp; Dubner), <em>Blink</em> (by Malcomn Gladwell) and <em>The Checklist Manifesto</em> (by Atul Gawande).</p>
<p>He continued his talk mentioning the different types of problems and why software development is a complex problem. With this in mind he spoke about agility and complexity going to the process of Discovery (What &amp; Why) -&gt; Delivery (How &amp; When). In the middle we find the &#8220;Pivot&#8221; and the continuous product learning.</p>
<p>In the end he showed us the Dude&#8217;s Law which basically is Value = Why / How. Another great speech by David Hussman.</p>
<h2>James Lewis &#8211; Agile Adoption Anti-Patterns</h2>
<p>On the second day of presentations I started watching this presentation about the anti-patterns to agile adoption. <a href="http://bovon.org/">James Lewis</a> works for <a href="http://www.thoughtworks.com/">ThoughtWorks</a> and has a great experience introducing agile in large organizations.</p>
<p>The first part of his presentation was focused on enumerating the anti-patterns and explaining them. Things like &#8220;Flaccid Technical Lead&#8221;, &#8220;Novice in Charge&#8221;, &#8220;Change Everything at Once&#8221; and &#8220;Agile Adapter&#8221; made me remember some things&#8230; But, continuing with the presentation, James showed us the root causes of the anti-patterns and why it&#8217;s so hard to change.</p>
<p>Next he showed some ideas of what should be done when we aim at individual change and change to teams. He talked about the <a href="http://en.wikipedia.org/wiki/Dreyfus_model_of_skill_acquisition">Dreyfus Model of Skill Acquisition</a> and how it applies to pair programming and also talked about the <a href="http://en.wikipedia.org/wiki/Conway's_Law">Conway&#8217;s Law</a>. He ended with two phrases: &#8220;Do the wrong thing righter&#8221; and &#8220;Do the right thing&#8221;.</p>
<h2>Klaus Wuestefeld &#8211; Learning and Coolness &#8211; Beyond XP (Keynote)</h2>
<p>Klaus Wuestefeld is a pioneer in the extreme programming in Brazil. He has already done pair programming with well know names like Kent Beck and Scott Ambler. In his presentation he spoke about how he is doing XP today.</p>
<p>He began his presentation speaking about his background. He created <a href="http://www.prevayler.org/">Prevayler</a> and other open source initiatives. Later he discussed several characteristics of the software development process, like the fact that software is a fractal, and the agile methods. After this overview he talked about the values of the software development and why it should be a balance between Learning and Coolness.</p>
<p>To finish his talk, he talked about the practices he thinks that matter most. He mention that he doesn&#8217;t use Scrum, Iterations, Issue Tracking, Continuous Build and Branches. On the other hand, he adopts several practices like Planning on Demand, Continuous Deployment, Cleaners and Pair Programming, just to mention some of them.</p>
<h1>Conclusion</h1>
<p>This event was a great opportunity for the agile community. We saw some of the big names of agile here. I didn&#8217;t wrote too much here, because I think that the presentations are&#8217;t freely distributed. So, if you&#8217;re interested in the topic, you should search for some of the names I wrote here. Besides, there are a lot of events on the topic around the world. I also want to leave here a big thanks to the organization committee. Thanks for visiting!</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=N9CT8XXl75Q:SZITUr02GU0:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=N9CT8XXl75Q:SZITUr02GU0:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=N9CT8XXl75Q:SZITUr02GU0:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=N9CT8XXl75Q:SZITUr02GU0:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/methodologies/agile-brazil-2010-brazilian-conference-on-agile-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a WordPress Theme (Part 5): Pages and Posts</title>
		<link>http://oscardias.com/wordpress/creating-a-wordpress-theme-part-5-pages-and-posts/</link>
		<comments>http://oscardias.com/wordpress/creating-a-wordpress-theme-part-5-pages-and-posts/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 21:41:04 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=75</guid>
		<description><![CDATA[In this part of the series we&#8217;re going to create the templates used for pages and posts. The page template is very simple because it only has the basic structure of our design. The post template has more details, which makes it more complex. In order to complete the post page, we&#8217;re also going to [...]]]></description>
			<content:encoded><![CDATA[<p><em>In this part of the series we&#8217;re going to create the templates used for pages and posts. The page template is very simple because it only has the basic structure of our design. The post template has more details, which makes it more complex. In order to complete the post page, we&#8217;re also going to do the comments template.</em></p>
<p><em>The current file with the current theme can be downloaded <a href="http://oscardias.com/br/wp-content/uploads/2010/06/mytheme.zip">here</a>.</em></p>
<p><span id="more-75"></span></p>
<h1>Introduction</h1>
<p>We start this part of the series with our theme partially done. We have already created the design, started with the CSS and coded most of our home page. Now we&#8217;re going to code the templates for pages and single posts. We want both templates to look like our home page, so it&#8217;s the same structure we&#8217;ve already seen.</p>
<p>At the end of this post you can find the previous parts of the series and catch up with the development.</p>
<h1>Pages</h1>
<p>If you create a page and check it with our current page template, this is what you&#8217;re going to see:</p>
<div id="attachment_136" class="wp-caption alignnone" style="width: 310px"><a href="http://oscardias.com/br/wp-content/uploads/2010/06/img01.png"><img class="size-medium wp-image-136" title="Single page before corrections" src="http://oscardias.com/br/wp-content/uploads/2010/06/img01-300x199.png" alt="Single page before corrections" width="300" height="199" /></a><p class="wp-caption-text">Single page before corrections</p></div>
<p>We&#8217;re going to fix this by updating the page template. As we used the Default theme to build our theme, we&#8217;re just going to update the PHP file. Most of the needed CSS is already defined. The images aren&#8217;t styled yet, but we&#8217;re going to do it later, for the single posts template.</p>
<h2>page.php</h2>
<ol>
<li>Open the page.php file.</li>
<li>Update the package information: replace @subpackage Default_Theme with @subpackage MyTheme_Theme.</li>
<li>Now replace all occurrences of &#8216;kubrick&#8217; with &#8216;mytheme&#8217;.</li>
<li>Let&#8217;s do the same we did for our home page and replace the &lt;div id=&#8221;content&#8221;&gt; with the 2 DIV&#8217;s that will define our structure:
<pre class="brush: php; title: ; notranslate">
&lt;div id=&quot;main&quot; class=&quot;container_12 box-shadow&quot;&gt;
    &lt;div id=&quot;content&quot; class=&quot;grid_8&quot; role=&quot;main&quot;&gt;
</pre>
</li>
<li>Remove the call to the wp_link_pages() function. This function is used to split the page in different pages using the &#8220;Page-Link&#8221; tag (&lt;!&#8211;nextpage&#8211;&gt;).</li>
<li>Now just close the DIV created in step 4, right after the get_sidebar() function, and add a DIV with &#8220;clear&#8221; class after the function call.</li>
</ol>
<p>Quite simple. The final code for the <em>page.php</em> file is the following:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * @package WordPress
 * @subpackage MyTheme_Theme
 */

get_header(); ?&gt;
&lt;div id=&quot;main&quot; class=&quot;container_12 box-shadow&quot;&gt;
	&lt;div id=&quot;content&quot; class=&quot;grid_8&quot; role=&quot;main&quot;&gt;

		&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
		&lt;div class=&quot;post&quot; id=&quot;post-&lt;?php the_ID(); ?&gt;&quot;&gt;
		&lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;
			&lt;div class=&quot;entry&quot;&gt;
				&lt;?php the_content('&lt;p class=&quot;serif&quot;&gt;' . __('Read the rest of this page &amp;raquo;', 'mytheme') . '&lt;/p&gt;'); ?&gt;

			&lt;/div&gt;
		&lt;/div&gt;
		&lt;?php endwhile; endif; ?&gt;
	&lt;?php edit_post_link(__('Edit this entry.', 'mytheme'), '&lt;p&gt;', '&lt;/p&gt;'); ?&gt;

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

	&lt;/div&gt;

&lt;?php get_sidebar(); ?&gt;
    &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;?php get_footer(); ?&gt;
</pre>
<p>With this little update, this is the result:</p>
<div id="attachment_138" class="wp-caption alignnone" style="width: 310px"><a href="http://oscardias.com/br/wp-content/uploads/2010/06/img02.png"><img class="size-medium wp-image-138" title="Single page template" src="http://oscardias.com/br/wp-content/uploads/2010/06/img02-300x199.png" alt="Single page template" width="300" height="199" /></a><p class="wp-caption-text">Single page template</p></div>
<h1>Posts</h1>
<p>Before we start with the coding of the single post display we can see something similar to what we had for the pages:</p>
<div id="attachment_139" class="wp-caption alignnone" style="width: 264px"><a href="http://oscardias.com/br/wp-content/uploads/2010/06/img03.png"><img class="size-medium wp-image-139" title="Single post before changes" src="http://oscardias.com/br/wp-content/uploads/2010/06/img03-254x300.png" alt="Single post before changes" width="254" height="300" /></a><p class="wp-caption-text">Single post before changes</p></div>
<p>Once again the problem is that we haven&#8217;t added the 960.css classes. So let&#8217;s start with the PHP and do this. We&#8217;ll continue with some changes in the CSS.</p>
<h2>single.php</h2>
<ol>
<li>Change the package information to fit our theme name.</li>
<li>Update the &#8220;text domain&#8221; replacing all occurrences of &#8216;kubrick&#8217; with &#8216;mytheme&#8217;.</li>
<li>Replace the &lt;div id=&#8221;content&#8221;&gt; with 2 DIV&#8217;s with the 960.css classes:
<pre class="brush: php; title: ; notranslate">
&lt;div id=&quot;main&quot; class=&quot;container_12 box-shadow&quot;&gt;
    &lt;div id=&quot;content&quot; class=&quot;grid_8&quot; role=&quot;main&quot;&gt;
</pre>
</li>
<li>Before we call the function the_content() add a call to the post thumbnail function.
<p>                &lt;?php<br />
                    if ( has_post_thumbnail() ) {<br />
                        the_post_thumbnail();<br />
                    }</p>
<p>                    the_content(); ?&gt;
</li>
<li>Now we&#8217;re going to add a facebook Like button. So, add the following code after you call the function the_content():
<pre class="brush: php; title: ; notranslate">
                &lt;iframe src=&quot;http://www.facebook.com/plugins/like.php?href=&lt;?php echo urlencode(get_permalink($post-&gt;ID)); ?&gt;&amp;amp;layout=standard&amp;amp;show_faces=false&amp;amp;width=450&amp;amp;action=like&amp;amp;colorscheme=light&quot;
                        scrolling=&quot;no&quot;
                        frameborder=&quot;0&quot;
                        allowTransparency=&quot;true&quot;
                        class=&quot;facebooklike&quot;&gt;&lt;/iframe&gt;
</pre>
</li>
<li>Right after the functions wp_link_pages() and the_tags() we have the post metadata. Move it outside the &lt;div class=&#8221;entry&#8221;&gt;, after the &lt;/div&gt; that closes the entry content DIV. Also remove the class from the metadata paragraph because we already used this class in the home page.</li>
<li>Before we call the get_footer() function, add the sidebar and a clear with the following code:
<pre class="brush: php; title: ; notranslate">
&lt;?php get_sidebar(); ?&gt;
    &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
</li>
</ol>
<p>The complete code of the <em>single.php</em> file is this:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * @package WordPress
 * @subpackage MyTheme_Theme
 */

get_header();
?&gt;
&lt;div id=&quot;main&quot; class=&quot;container_12 box-shadow&quot;&gt;
    &lt;div id=&quot;content&quot; class=&quot;grid_8&quot; role=&quot;main&quot;&gt;

	&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;

		&lt;div class=&quot;navigation&quot;&gt;
			&lt;div class=&quot;alignleft&quot;&gt;&lt;?php previous_post_link('&amp;laquo; %link') ?&gt;&lt;/div&gt;
			&lt;div class=&quot;alignright&quot;&gt;&lt;?php next_post_link('%link &amp;raquo;') ?&gt;&lt;/div&gt;
		&lt;/div&gt;

		&lt;div &lt;?php post_class(); ?&gt; id=&quot;post-&lt;?php the_ID(); ?&gt;&quot;&gt;
			&lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;

			&lt;div class=&quot;entry&quot;&gt;
                &lt;?php
                    if ( has_post_thumbnail() ) {
                        the_post_thumbnail();
                    }

                    the_content(); ?&gt;

                &lt;iframe src=&quot;http://www.facebook.com/plugins/like.php?href=&lt;?php echo urlencode(get_permalink($post-&gt;ID)); ?&gt;&amp;amp;layout=standard&amp;amp;show_faces=false&amp;amp;width=450&amp;amp;action=like&amp;amp;colorscheme=light&quot;
                        scrolling=&quot;no&quot;
                        frameborder=&quot;0&quot;
                        allowTransparency=&quot;true&quot;
                        class=&quot;facebooklike&quot;&gt;&lt;/iframe&gt;

				&lt;?php wp_link_pages(array('before' =&gt; '&lt;p&gt;&lt;strong&gt;' . __('Pages:', 'mytheme') . '&lt;/strong&gt; ', 'after' =&gt; '&lt;/p&gt;', 'next_or_number' =&gt; 'number')); ?&gt;
				&lt;?php the_tags( '&lt;p&gt;' . __('Tags:', 'mytheme') . ' ', ', ', '&lt;/p&gt;'); ?&gt;

			&lt;/div&gt;
				&lt;p&gt;
					&lt;small&gt;
						&lt;?php /* This is commented, because it requires a little adjusting sometimes.
							You'll need to download this plugin, and follow the instructions:
							http://binarybonsai.com/wordpress/time-since/ */
							/* $entry_datetime = abs(strtotime($post-&gt;post_date) - (60*120)); $time_since = sprintf(__('%s ago', 'mytheme'), time_since($entry_datetime)); */ ?&gt;
						&lt;?php printf(__('This entry was posted %1$s on %2$s at %3$s and is filed under %4$s.', 'mytheme'), $time_since, get_the_time(__('l, F jS, Y', 'mytheme')), get_the_time(), get_the_category_list(', ')); ?&gt;
						&lt;?php printf(__(&quot;You can follow any responses to this entry through the &lt;a href='%s'&gt;RSS 2.0&lt;/a&gt; feed.&quot;, &quot;mytheme&quot;), get_post_comments_feed_link()); ?&gt;

						&lt;?php if ( comments_open() &amp;&amp; pings_open() ) {
							// Both Comments and Pings are open ?&gt;
							&lt;?php printf(__('You can &lt;a href=&quot;#respond&quot;&gt;leave a response&lt;/a&gt;, or &lt;a href=&quot;%s&quot; rel=&quot;trackback&quot;&gt;trackback&lt;/a&gt; from your own site.', 'mytheme'), trackback_url(false)); ?&gt;

						&lt;?php } elseif ( !comments_open() &amp;&amp; pings_open() ) {
							// Only Pings are Open ?&gt;
							&lt;?php printf(__('Responses are currently closed, but you can &lt;a href=&quot;%s&quot; rel=&quot;trackback&quot;&gt;trackback&lt;/a&gt; from your own site.', 'mytheme'), trackback_url(false)); ?&gt;

						&lt;?php } elseif ( comments_open() &amp;&amp; !pings_open() ) {
							// Comments are open, Pings are not ?&gt;
							&lt;?php _e('You can skip to the end and leave a response. Pinging is currently not allowed.', 'mytheme'); ?&gt;

						&lt;?php } elseif ( !comments_open() &amp;&amp; !pings_open() ) {
							// Neither Comments, nor Pings are open ?&gt;
							&lt;?php _e('Both comments and pings are currently closed.', 'mytheme'); ?&gt;

						&lt;?php } edit_post_link(__('Edit this entry', 'mytheme'),'','.'); ?&gt;

					&lt;/small&gt;
				&lt;/p&gt;
		&lt;/div&gt;

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

	&lt;?php endwhile; else: ?&gt;

		&lt;p&gt;&lt;?php _e('Sorry, no posts matched your criteria.', 'mytheme'); ?&gt;&lt;/p&gt;

&lt;?php endif; ?&gt;

	&lt;/div&gt;
    &lt;?php get_sidebar(); ?&gt;
    &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;?php get_footer(); ?&gt;
</pre>
<p>Now let&#8217;s go to the CSS.</p>
<h2>style.css</h2>
<ol>
<li>First we&#8217;ll define the .navigation class. We need some margin at the top and bottom.
<pre class="brush: css; title: ; notranslate">
.navigation {
    overflow:hidden;
    margin-top: 10px;
    margin-bottom: 15px;
}</pre>
</li>
<li>Next we&#8217;ll define the images with captions. Let&#8217;s align the text, add a gray border and a box-shadow (CSS3 property &#8211; only for modern browsers).
<pre class="brush: css; title: ; notranslate">
.wp-caption {
    text-align: center;
    padding-top: 4px;
    margin: 10px auto;
    border: 1px solid #808080;
    -moz-box-shadow: 2px 2px 2px #555; /* for Firefox 3.5+ */
    -webkit-box-shadow: 2px 2px 2px #555; /* for Safari and Chrome */
}
</pre>
</li>
<li>Continue centering the image and defining the caption size.
<pre class="brush: css; title: ; notranslate">
.wp-caption img {
    margin-left: auto;
    margin-right: auto;
    border:0;
}
.wp-caption p.wp-caption-text {
    font-size: 0.8em;
    padding-top: 5px;
    margin: 0;
}
</pre>
</li>
<li>Let&#8217;s finish it defining the size of the facebook Like IFRAME.
<pre class="brush: css; title: ; notranslate">
.facebooklike {
    border:none;
    overflow:hidden;
    width:450px;
    height:40px;
}</pre>
</li>
</ol>
<h1>Comments</h1>
<p>We&#8217;ve coded the single post template, but we still need to code the comments template in order to finish it.</p>
<h2>comments.php</h2>
<ol>
<li>First, replace all occurrences of &#8216;kubrick&#8217; with &#8216;mytheme&#8217;.</li>
<li>Then add the class &#8220;text-shadow&#8221; to the comments INPUT tag.</li>
</ol>
<p>Few changes in the PHP file, but a lot more in the CSS file.</p>
<h2>style.css</h2>
<ol>
<li>Let&#8217;s start with the .nocomments class. We need to align the text and add some margin.
<pre class="brush: css; title: ; notranslate">
.nocomments {
    text-align: center;
    margin: 10px;
    padding: 0;
}
</pre>
</li>
<li>Now we have to define the comment list. Add a dotted green border and remove the list style.
<pre class="brush: css; title: ; notranslate">
.commentlist {
    padding: 0;
    text-align: justify;
}
.commentlist li {
    font-weight: bold;
    margin: 15px 0 0;
    padding: 5px 5px 10px 10px;
    list-style: none;
    border: 1px dotted #008800;
}
</pre>
</li>
<li>Float the avatar image to the right and add a gray border.
<pre class="brush: css; title: ; notranslate">
.commentlist li .avatar {
    float: right;
    border: 1px solid #808080;
    padding: 2px;
    background: #d2d2d2;
}
</pre>
</li>
<li>Each comment have a class to indicate if it&#8217;s odd or even, so let&#8217;s define different background to each of them.
<pre class="brush: css; title: ; notranslate">
.commentlist li.odd {
    background: #f6f6f6;
}
.commentlist li.even {
    background: #fff;
}
</pre>
</li>
<li>As we may have comment&#8217;s replys, we need to style lists inside lists.
<pre class="brush: css; title: ; notranslate">
.commentlist li ul li {
    margin-right: -5px;
    margin-left: -15px;
}
.commentlist li.depth-2, .commentlist li.depth-3, .commentlist li.depth-4, .commentlist li.depth-5 {
    background: transparent;
}
.commentlist li.parent {
    padding-bottom: 0;
}
</pre>
</li>
<li>Now we need to style the comment&#8217;s paragraphs and the comment&#8217;s metadata::
<pre class="brush: css; title: ; notranslate">
.commentlist p {
    font-weight: normal;
    line-height: 1.5em;
    margin: 10px 5px 10px 0;
}
.commentmetadata {
    margin: 5px 0;
}
</pre>
</li>
<li>We&#8217;ll finish by styling the comment&#8217;s form.
<pre class="brush: plain; title: ; notranslate">
#commentform {
    margin: 5px 10px 0 0;
}
#commentform input {
    width: 170px;
    padding: 2px;
    margin: 5px 5px 1px 0;
}
#commentform textarea {
    width: 100%;
    padding: 2px;
}
#commentform #submit {
    margin: 0 0 5px auto;
    float: right;
    background: #006600;
    border:1px solid #008800;
    color:#fff;
    font-weight: bold;
    cursor: pointer;
}
#commentform p {
    margin: 5px 0;
}
#respond:after {
    content: &quot;.&quot;;
    display: block;
    height: 0;
    clear: both;
    visibility: hidden;
}
</pre>
</li>
</ol>
<p>With the last changes we have also finished our single post page. Here is the result:</p>
<div id="attachment_147" class="wp-caption alignnone" style="width: 207px"><a href="http://oscardias.com/br/wp-content/uploads/2010/06/img04.png"><img class="size-medium wp-image-147" title="Single post" src="http://oscardias.com/br/wp-content/uploads/2010/06/img04-197x300.png" alt="Single post" width="197" height="300" /></a><p class="wp-caption-text">Single post</p></div>
<h1>Conclusion</h1>
<p>With this post we have finished the main templates of our theme. Very simple changes, similar to what we&#8217;ve done for our home page. The theme is almost 100% functional. There are some missing templates, like <em>links.php</em>, <em>archive.php</em> and <em>archives.php</em>, that are easily updated doing the similar changes as we&#8217;ve done for the <em>page.php</em> file. For this reason, I&#8217;m not going to show these templates here. It&#8217;s just a repetition of what we&#8217;ve done.</p>
<p class="downloadnote">Download our theme with the changes we made in this post <a href="http://oscardias.com/br/wp-content/uploads/2010/06/mytheme1.zip">here</a> (76 Kb).</p>
<p>Next week I plan to finish these series about the WordPress theme creation. We&#8217;ll see the footer, some additional styling and the widgets I use. Thanks for the visit and don&#8217;t forget to come back for the last part.</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></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=QJHnMH0nf5Y:jrm-kyNkYXg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=QJHnMH0nf5Y:jrm-kyNkYXg:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=QJHnMH0nf5Y:jrm-kyNkYXg:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=QJHnMH0nf5Y:jrm-kyNkYXg:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/wordpress/creating-a-wordpress-theme-part-5-pages-and-posts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a WordPress Theme (Part 4): Home Page</title>
		<link>http://oscardias.com/wordpress/creating-a-wordpress-theme-part-4-home-page/</link>
		<comments>http://oscardias.com/wordpress/creating-a-wordpress-theme-part-4-home-page/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 11:02:29 +0000</pubDate>
		<dc:creator>Oscar Dias</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[theme]]></category>

		<guid isPermaLink="false">http://oscardias.com/?p=66</guid>
		<description><![CDATA[As we continue with our theme&#8217;s development, I&#8217;ll show you in this article what changes we need in our index.php. So we&#8217;ll continue changing the files we copied from the Default theme and we&#8217;ll create new CSS styles. In order to complete the main part of our home page, we&#8217;ll also prepare our sidebar and [...]]]></description>
			<content:encoded><![CDATA[<p><em>As we continue with our theme&#8217;s development, I&#8217;ll show you in this article what changes we need in our index.php. So we&#8217;ll continue changing the files we copied from the Default theme and we&#8217;ll create new CSS styles. In order to complete the main part of our home page, we&#8217;ll also prepare our sidebar and add some functions to our theme.</em></p>
<p><em>If you didn&#8217;t read the previous article, <a href="http://oscardias.com/br/wp-content/uploads/2010/05/mytheme.zip">click here</a> to download our theme&#8217;s files.</em></p>
<p><span id="more-66"></span></p>
<h1>Introduction</h1>
<p>In the <a href="http://oscardias.com/wordpress/creating-a-wordpress-theme-part-3-header/">previous article</a> we copied the Default theme (which comes with WordPress 2.9) and started our development by changing its header (<em>header.php</em>). We also defined different styles in the <em>style.css</em>. Today we&#8217;ll continue our development by coding our home page and the <em>index.php</em> file.</p>
<p>So far this is how our theme looks like:</p>
<div id="attachment_108" class="wp-caption alignnone" style="width: 310px"><a href="http://oscardias.com/br/wp-content/uploads/2010/05/27-5-2010-19-13-43.jpg"><img class="size-medium wp-image-108  " title="Our theme with the header" src="http://oscardias.com/br/wp-content/uploads/2010/05/27-5-2010-19-13-43-300x120.jpg" alt="Our theme with the header" width="300" height="120" /></a><p class="wp-caption-text">Our theme with the header</p></div>
<p>As you can see we have everything ready until our menu. The post title appears next to the menu. Now we&#8217;re going to fix this.</p>
<h1>PHP Development</h1>
<p>Please open the <em>index.php</em> file from our theme (<em>wp-content/mytheme</em>). The code is the original one from the Default theme, so let&#8217;s do the necessary changes. Besides this file, we&#8217;ll also create some functions and correct our sidebar.</p>
<p>As we&#8217;re using the 960.css (<a href="http://960.gs/">960 Grid System</a>) we need to insert our content in a new container. The container will have 12 columns, 8 columns for the main content and 4 columns for the sidebar (this will be defined inside <em>sidebar.php</em>). So, the structure of our <em>index.php</em> will be:</p>
<pre class="brush: php; title: ; notranslate">

&lt;div id=&quot;main&quot; class=&quot;container_12 box-shadow&quot;&gt;
    &lt;div id=&quot;content&quot; class=&quot;grid_8&quot; role=&quot;main&quot;&gt;
    &lt;/div&gt;
    &lt;?php get_sidebar(); ?&gt;
    &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
</pre>
<h2>Home Page</h2>
<ol>
<li>As we did the last time, change the subpackage information at the first lines: replace @subpackage Default_Theme with @subpackage MyTheme_Theme</li>
<li>In order to speed thing up, also replace all occurrences of &#8216;kubrick&#8217; with &#8216;mytheme&#8217;. This will update the default text domain for our own text domain which will be used for translation later.</li>
<li>Now replace also the &lt;div id=&#8221;content&#8221;&gt; with 2 div&#8217;s which will define our structure:
<pre class="brush: php; title: ; notranslate">

&lt;div id=&quot;main&quot; class=&quot;container_12 box-shadow&quot;&gt;
    &lt;div id=&quot;content&quot; class=&quot;grid_8&quot; role=&quot;main&quot;&gt;
</pre>
</li>
<li>Inside the tag &lt;small&gt; we&#8217;ll change the post information. We&#8217;ll include the author, the date and the number of commetns:
<pre class="brush: php; title: ; notranslate">
&lt;small&gt;&lt;?php _e('By', 'mytheme'); ?&gt; &lt;?php the_author(); ?&gt; &lt;?php _e('on', 'mytheme'); ?&gt; &lt;?php the_time(__('F jS, Y', 'mytheme')); ?&gt; &lt;?php if ( comments_open() ) _e('with', 'mytheme'); ?&gt; &lt;?php comments_popup_link(__('No Comments &amp;#187;', 'mytheme'), __('1 Comment &amp;#187;', 'mytheme'), __('% Comments &amp;#187;', 'mytheme'), '', __('Comments Closed', 'mytheme') ); ?&gt;&lt;/small&gt;
</pre>
</li>
<li>The next step is to replace the simple call for the function the_content() &#8211; which shows the post content, of course &#8211; with another code that will also show the post&#8217;s thumbnail:
<pre class="brush: php; title: ; notranslate">
&lt;?php
if ( has_post_thumbnail() ) {
    the_post_thumbnail();
}

the_content(__('Read more &amp;raquo;', 'mytheme')); ?&gt;
</pre>
</li>
<li>Now we need to remove the number of comments from the post metadata paragraph. Besides, we&#8217;ll also add a &#8220;clear&#8221; DIV before the metadata because we&#8217;re going to use float for the thumbnail and the &#8220;clear&#8221; will force the metadata into the next line. The code will look like this:
<pre class="brush: php; title: ; notranslate">
&lt;?php
&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;p class=&quot;postmetadata&quot;&gt;&lt;?php the_tags(__('Tags:', 'mytheme') . ' ', ', ', '&lt;br /&gt;'); ?&gt; &lt;?php printf(__('Posted in %s', 'mytheme'), get_the_category_list(', ')); ?&gt; &lt;?php edit_post_link(__('Edit', 'mytheme'), ' | ', ' | '); ?&gt;  &lt;/p&gt;
</pre>
</li>
<li>Close the DIV we created in step 3, but put the get_sidebar() function inside it. Also add another &#8220;clear&#8221; after this function.</li>
</ol>
<p>The complete code for the <em>index.php</em> file is the following:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * @package WordPress
 * @subpackage MyTheme_Theme
 */

get_header(); ?&gt;
&lt;div id=&quot;main&quot; class=&quot;container_12 box-shadow&quot;&gt;
    &lt;div id=&quot;content&quot; class=&quot;grid_8&quot; role=&quot;main&quot;&gt;

	&lt;?php if (have_posts()) : ?&gt;

		&lt;?php while (have_posts()) : the_post(); ?&gt;

			&lt;div &lt;?php post_class(); ?&gt; id=&quot;post-&lt;?php the_ID(); ?&gt;&quot;&gt;
				&lt;h2&gt;&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot; title=&quot;&lt;?php printf(__('Permanent Link to %s', 'mytheme'), the_title_attribute('echo=0')); ?&gt;&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;
				&lt;small&gt;&lt;?php _e('By', 'mytheme'); ?&gt; &lt;?php the_author(); ?&gt; &lt;?php _e('on', 'mytheme'); ?&gt; &lt;?php the_time(__('F jS, Y', 'mytheme')); ?&gt; &lt;?php if ( comments_open() ) _e('with', 'mytheme'); ?&gt; &lt;?php comments_popup_link(__('No Comments &amp;#187;', 'mytheme'), __('1 Comment &amp;#187;', 'mytheme'), __('% Comments &amp;#187;', 'mytheme'), '', __('Comments Closed', 'mytheme') ); ?&gt;&lt;/small&gt;

				&lt;div class=&quot;entry&quot;&gt;
                                    &lt;?php
                                        if ( has_post_thumbnail() ) {
                                            the_post_thumbnail();
                                        }

                                        the_content(__('Read more &amp;raquo;', 'mytheme')); ?&gt;
				&lt;/div&gt;

                                &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
				&lt;p class=&quot;postmetadata&quot;&gt;&lt;?php the_tags(__('Tags:', 'mytheme') . ' ', ', ', '&lt;br /&gt;'); ?&gt; &lt;?php printf(__('Posted in %s', 'mytheme'), get_the_category_list(', ')); ?&gt; &lt;?php edit_post_link(__('Edit', 'mytheme'), ' | ', ' | '); ?&gt;  &lt;/p&gt;
			&lt;/div&gt;

		&lt;?php endwhile; ?&gt;

		&lt;div class=&quot;navigation&quot;&gt;
			&lt;div class=&quot;alignleft&quot;&gt;&lt;?php next_posts_link(__('&amp;laquo; Older Entries', 'mytheme')) ?&gt;&lt;/div&gt;
			&lt;div class=&quot;alignright&quot;&gt;&lt;?php previous_posts_link(__('Newer Entries &amp;raquo;', 'mytheme')) ?&gt;&lt;/div&gt;
		&lt;/div&gt;

	&lt;?php else : ?&gt;

		&lt;h2 class=&quot;center&quot;&gt;&lt;?php _e('Not Found', 'mytheme'); ?&gt;&lt;/h2&gt;
		&lt;p class=&quot;center&quot;&gt;&lt;?php _e('Sorry, but you are looking for something that isn&amp;#8217;t here.', 'mytheme'); ?&gt;&lt;/p&gt;
		&lt;?php get_search_form(); ?&gt;

	&lt;?php endif; ?&gt;

	&lt;/div&gt;

    &lt;?php get_sidebar(); ?&gt;
    &lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;?php get_footer(); ?&gt;
</pre>
<p>If you go to your browser and check your website you&#8217;ll see a fatal error. That&#8217;s because we used the thumbnail functions without enabling it in our theme. Therefore we&#8217;ll need to do that by changing our <em>functions.php</em>.</p>
<h2>Creating the Functions</h2>
<p>Open the <em>functions.php</em> file and remove all the content.</p>
<ol>
<li>As we did for all the PHP files, insert the package information for our theme.</li>
<li>Right after that we&#8217;ll add the function that will be in charge of loading our text domain. First we have to add the function using add_action() and later we add the function itself:
<pre class="brush: php; title: ; notranslate">
add_action ('init','mytheme_init');

function mytheme_init (){
    load_theme_textdomain('mytheme', get_template_directory());
}
</pre>
</li>
<li>The next step is enabling the thumbnails by adding support in our theme. We&#8217;ll also define the thumb&#8217;s size. in our case it will have a width of 125 pixels, without constraints for the height.
<p>add_theme_support( &#8216;post-thumbnails&#8217;, array( &#8216;post&#8217; ) );<br />
set_post_thumbnail_size( 125, 9999 );
</li>
<li>Now we&#8217;ll register our sidebar and define the tags used inside it.
<pre class="brush: php; title: ; notranslate">
if ( function_exists('register_sidebar') ) {
	register_sidebar(array(
		'before_widget' =&gt; '&lt;li id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;',
		'after_widget' =&gt; '&lt;/li&gt;',
		'before_title' =&gt; '&lt;h2 class=&quot;widgettitle&quot;&gt;',
		'after_title' =&gt; '&lt;/h2&gt;',
	));
}
</pre>
</li>
</ol>
<p>If you go to your browser again, you&#8217;ll see that the theme is working again.</p>
<h2>Sidebar</h2>
<p>Let&#8217;s finish the PHP part of this post updating the file <em>sidebar.php</em>. As it&#8217;s a small file, let&#8217;s simply remove all the content and add the following:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
/**
 * @package WordPress
 * @subpackage MyTheme_Theme
 */
?&gt;
&lt;div id=&quot;sidebar&quot; class=&quot;grid_4&quot; role=&quot;complementary&quot;&gt;
    &lt;ul&gt;
        &lt;?php /* Widgetized sidebar, if you have the plugin installed. */
            if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?&gt;
            &lt;li&gt;&lt;h2&gt;&lt;?php _e('Archives', 'mytheme'); ?&gt;&lt;/h2&gt;
                &lt;ul&gt;
                &lt;?php wp_get_archives('type=monthly'); ?&gt;
                &lt;/ul&gt;
            &lt;/li&gt;
        &lt;?php endif; ?&gt;
    &lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>Here we define the size of 4 columns by using grid_4. We used here the dynamic_sidebar() function to check if the widgetized sidebar is enabled. In case it&#8217;s not enabled we&#8217;ll show only the blog archives.</p>
<p>This is how our theme looks before we add the new styles:</p>
<div id="attachment_125" class="wp-caption alignnone" style="width: 310px"><a href="http://oscardias.com/br/wp-content/uploads/2010/06/5-6-2010-18-16-28.jpg"><img class="size-medium wp-image-125 " title="Theme before the new styles" src="http://oscardias.com/br/wp-content/uploads/2010/06/5-6-2010-18-16-28-300x279.jpg" alt="Theme before the new styles" width="300" height="279" /></a><p class="wp-caption-text">Theme before the new styles</p></div>
<p>So now let&#8217;s go to our CSS.</p>
<h1>Style Definition in the CSS</h1>
<p>Open the <em>style.css</em> file from our theme. First we&#8217;ll add the index page styles and later the sidebar ones.</p>
<h2>Index Page</h2>
<ol>
<li>Let&#8217;s start with the &lt;div id=&#8221;main&#8221;&gt;. We&#8217;ll define it with a white background, green (#008800) border with a border-radius. We&#8217;re going to define margin and padding too.
<pre class="brush: css; title: ; notranslate">
#main {
    background-color: white;
    border: 2px solid #008800;
    border-radius:10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    margin: 32px auto;
    padding: 20px 0;
}
</pre>
</li>
<li>Next, we&#8217;ll define the font details for the post entries.
<pre class="brush: css; title: ; notranslate">
.entry {
    font-size: 1.4em;
    text-align: justify;
    line-height: 1.5em;
}
</pre>
</li>
<li>Now we have to add the different sizes for the headers. We&#8217;ll also add a border on the top of the header in order to have a better separation among sections.
<pre class="brush: css; title: ; notranslate">
.entry h1, .entry h2, .entry h3, .entry h4 {
    color: #000;
    border-top: 1px dotted #afa;
}
.entry h1 {
    font-size: 1.8em;
    padding: 25px 0 0 0;
    margin: 25px 0;
}
.entry h2 {
    font-size: 1.6em;
    padding: 15px 0 0 0;
    margin: 15px 0;
}
.entry h3 {
    font-size: 1.4em;
    padding: 10px 0 0 0;
    margin: 10px 0;
}
.entry h4 {
    font-size: 1.2em;
    padding: 5px 0 0 0;
    margin: 5px 0;
}
</pre>
</li>
<li>Align the thumbnail by adding a float to it. Also add a border to it.
<pre class="brush: css; title: ; notranslate">
.attachment-post-thumbnail {
    float:left;
    margin:4px 8px 4px 0;
    padding:0;
    background: #d2d2d2;
    border: 1px solid #808080;
    border-radius:10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
}
</pre>
</li>
<li>The last thing is to define the metadata:
<pre class="brush: css; title: ; notranslate">
.postmetadata {
    font-size: 1.2em;
    line-height: 1.5em;
}
</pre>
</li>
</ol>
<h2>Sidebar</h2>
<ol>
<li>We&#8217;ll start the sidebar by defining the border that will make it appear.
<pre class="brush: css; title: ; notranslate">
#sidebar {
    border: 2px solid #008800;
    border-radius:10px;
    -moz-border-radius: 10px;
    -webkit-border-radius: 10px;
    margin: 15px 8px;
}
</pre>
</li>
<li>Next, we&#8217;ll remove the list styles and the padding:
<pre class="brush: css; title: ; notranslate">
#sidebar ul {
    list-style: none;
    padding:0;
}
</pre>
</li>
<li>And now we&#8217;ll fix the H2 headers, which we used when we registered our sidebar (in the <em>functions.php</em>).
<pre class="brush: css; title: ; notranslate">
#sidebar h2 {
    background: #006600;
    color: #fff;
    padding: 5px;
    border-top: 2px solid #008800;
    border-bottom: 2px solid #008800;
    text-shadow: #000 2px 2px 2px;
}
#sidebar h2 a {
    color: #fff;
}
</pre>
</li>
<li>As there are different HTML structure for the widgets, we&#8217;re going to define the spacing inside widgets in different ways.
<pre class="brush: css; title: ; notranslate">
#sidebar ul li ul {
    font-size: 1.4em;
    padding: 5px;
}
#sidebar div {
    font-size: 1.4em;
    padding: 5px;
    text-align: justify;
    line-height: 1.5em;
}
#sidebar table {
    font-size: 1.4em;
    padding: 5px;
}
#sidebar div div {
    font-size: 1em;
    padding: 0;
}
#sidebar ul div ul {
    font-size: 1em;
    padding: 0;
}
</pre>
</li>
</ol>
<p>So now we have finished our theme&#8217;s home page (except the footer). This is the result so far:</p>
<div id="attachment_126" class="wp-caption alignnone" style="width: 295px"><a href="http://oscardias.com/br/wp-content/uploads/2010/06/My-Theme_1275775017099.png"><img class="size-medium wp-image-126 " title="Our theme's home page" src="http://oscardias.com/br/wp-content/uploads/2010/06/My-Theme_1275775017099-285x300.png" alt="Our theme's home page" width="285" height="300" /></a><p class="wp-caption-text">Our theme&#39;s home page</p></div>
<h1>Conclusion</h1>
<p>In this article we continued our theme&#8217;s development by updating it&#8217;s home page. We&#8217;ve also created some function inside our <em>functions.php</em>, which allows us to enable and/or create some functionalities.</p>
<p class="downloadnote"><a href="http://oscardias.com/br/wp-content/uploads/2010/06/mytheme.zip">Click here</a> (75 Kb) to download the current version of our theme.</p>
<p>In our next post we&#8217;ll continue our theme&#8217;s development preparing the templates used for single posts and pages. From the next part we&#8217;ll reuse a lot of styles and the PHP files will look similar because our structure will be almost the same for different files. Once again, thanks for the visit!</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></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/oscardias?a=vEonbDpXRI4:YJZIa7xVR7Q:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/oscardias?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=vEonbDpXRI4:YJZIa7xVR7Q:-BTjWOF_DHI"><img src="http://feeds.feedburner.com/~ff/oscardias?i=vEonbDpXRI4:YJZIa7xVR7Q:-BTjWOF_DHI" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/oscardias?a=vEonbDpXRI4:YJZIa7xVR7Q:qj6IDK7rITs"><img src="http://feeds.feedburner.com/~ff/oscardias?d=qj6IDK7rITs" border="0"></img></a>
</div>]]></content:encoded>
			<wfw:commentRss>http://oscardias.com/wordpress/creating-a-wordpress-theme-part-4-home-page/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

