<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	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/"
	>

<channel>
	<title>Emanuele Feronato &#187; WordPress</title>
	<atom:link href="http://www.emanueleferonato.com/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emanueleferonato.com</link>
	<description>italian geek and PROgrammer</description>
	<lastBuildDate>Mon, 06 Feb 2012 14:28:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Triqui arcade theme for WordPress updated</title>
		<link>http://www.emanueleferonato.com/2011/10/31/triqui-arcade-theme-for-wordpress-updated/</link>
		<comments>http://www.emanueleferonato.com/2011/10/31/triqui-arcade-theme-for-wordpress-updated/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 18:19:55 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=4790</guid>
		<description><![CDATA[WordPress Arcade theme and plugin updated, by Luca Prosepio]]></description>
			<content:encoded><![CDATA[<p>While I am working on a new version of my <a href="http://www.emanueleferonato.com/triqui-mochiads-arcade-theme-for-wordpress-official-page/">WordPress arcade theme</a>, there are some known issues in the current theme which should be fixed.</p>
<p><strong>Luca Prosepio</strong> updated both the <a href="http://www.emanueleferonato.com/triqui-mochiads-arcade-theme-for-wordpress-official-page/">theme</a> and the <a href="http://www.emanueleferonato.com/triqui-mochiads-arcade-plugin-for-wordpress-official-page/">plugin</a> and you can see them working on <a href="http://www.giochi-gratuiti.com/" target="_blank">www.giochi-gratuiti.com</a>.</p>
<p><a href = "/wp-content/uploads/2011/10/themeplugin.zip">Download both the theme and the plugin</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/10/31/triqui-arcade-theme-for-wordpress-updated/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>How to display (some) WordPress sidebar widgets in random order</title>
		<link>http://www.emanueleferonato.com/2011/06/23/how-to-display-some-wordpress-sidebar-widgets-in-random-order/</link>
		<comments>http://www.emanueleferonato.com/2011/06/23/how-to-display-some-wordpress-sidebar-widgets-in-random-order/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 14:28:50 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=4333</guid>
		<description><![CDATA[A quick and dirty way to shuffle widgets position, since I did not find any plugin to do it.]]></description>
			<content:encoded><![CDATA[<p>Do you need a plugin to display WordPress sidebar widgets in random order? You won&#8217;t find it. Or you will find messy scripts which need to be tweaked to return some kind of result.</p>
<p>That&#8217;s why I made my 22 lines script to display my sidebar widgets in random order. And not just in &#8220;random order&#8221;, because I needed to keep some widgets in fixed positions, and having the remaining ones rotating.</p>
<p><strong>Motivation</strong></p>
<p>Once I <a href="http://www.emanueleferonato.com/2011/06/10/removing-all-ads-from-the-blog/">removed Adsense and network ads</a> from the blog I received a lot of sponsorship requests.</p>
<p>There&#8217;s nothing wrong with the ones I denied, it&#8217;s just they do not match with the content of the blog. </p>
<p>Anyway, as I am doing some minor changes to the blog, I am starting to place the supporters in the sidebar.</p>
<p>Every block is a widget created from the Appearence menu this way:</p>
<p><img src="/wp-content/uploads/2011/06/widgets.jpg" /></p>
<p>And what I want is having the first and the last widgets (respectively the twitter &#8220;Follow me&#8221; button and the Facebook fan widget) to remain fixed in their first and last position, while the remaining widget should be displayed in random order.</p>
<p>Saying it quick, I needed a script to display in random order widgets from the i-th to the j-th</p>
<p><strong>The theory</strong></p>
<p>If you theme is designed according to WP guidelines, your sidebar.php file should contain something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;div class=&quot;sidebar&quot;&gt;
	&lt;ul&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/ul&gt;
&lt;/div&gt;</pre></div></div>

<p>Where <code>dynamic_sidebar</code> function calls each of the active widget callbacks in order, and outputs the sidebar itself.</p>
<p>The generated html is something like this one:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;li id=&quot;some_id&quot; class=&quot;widget widget_text&quot;&gt;1st Widget content&lt;/li&gt;
&lt;li id=&quot;some_id&quot; class=&quot;widget widget_text&quot;&gt;2nd Widget content&lt;/li&gt;
...
&lt;li id=&quot;some_id&quot; class=&quot;widget widget_text&quot;&gt;i-th Widget content&lt;/li&gt;</pre></div></div>

<p>At this time, since there aren&#8217;t <a target = "_blank" href="http://codex.wordpress.org/Plugin_API">hooks</a> to handle widget output, we have to save the generated html, break it into individual widgets&#8217; html, and mix it as required.</p>
<p><strong>The code</strong></p>
<p>The following code shouldn&#8217;t be copied and pasted, and assumes you haven&#8217;t lists inside your widgets. But it can give you a brief idea of what you&#8217;re supposed to do.</p>
<p>First, call your sidebar in <code>sidebar.php</code> this way:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;div class=&quot;sidebar&quot;&gt;
	&lt;ul&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>random_widgets<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Sidebar'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/ul&gt;
&lt;/div&gt;</pre></div></div>

<p>I am calling <code>random_widgets</code> function rather than <code>dynamic_sidebar</code>.</p>
<p>The arguments are the sidebar name, the index of the first widget to be shuffled and the index of the last widget to be shuffled. Every widget outside such indexes won&#8217;t be shuffled.</p>
<p><code>random_widgets</code> function is defined inside <code>functions.php</code></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> random_widgets<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sidebar</span><span style="color: #339933;">,</span><span style="color: #000088;">$random_start</span><span style="color: #339933;">,</span><span style="color: #000088;">$random_end</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$widgets</span> <span style="color: #339933;">=</span> dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$sidebar</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$widgets</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     	<span style="color: #000088;">$html</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #000088;">$widgets_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;li&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #000088;">$head</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_slice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$widgets_array</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$random_start</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    		<span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_slice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$widgets_array</span><span style="color: #339933;">,</span> <span style="color: #000088;">$random_start</span><span style="color: #339933;">,</span> <span style="color: #000088;">$random_end</span><span style="color: #339933;">-</span><span style="color: #000088;">$random_start</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$tail</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_slice</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$widgets_array</span><span style="color: #339933;">,</span> <span style="color: #000088;">$random_end</span><span style="color: #339933;">+</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #990000;">shuffle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     	<span style="color: #000088;">$new_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$head</span><span style="color: #339933;">,</span><span style="color: #000088;">$body</span><span style="color: #339933;">,</span><span style="color: #000088;">$tail</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
     	<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$widget</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     	    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$widget</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     	         <span style="color: #000088;">$final_html</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;li&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$widget</span><span style="color: #339933;">;</span>
     	     <span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$final_html</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$final_html</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>What happens? I am saving the output inside a variable called <code>$html</code>. From such variable, I create an array with all widgets, break the array into sub arrays, shuffle the required array and rebuild the final code.</p>
<p>And that&#8217;s it, without installing any plugin. You can see the result refreshing the page, sidebar widgets will shuffle, with the only exception of the first and the last widgets, which remain in their place.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/06/23/how-to-display-some-wordpress-sidebar-widgets-in-random-order/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Wet Paint</title>
		<link>http://www.emanueleferonato.com/2011/04/21/wet-paint/</link>
		<comments>http://www.emanueleferonato.com/2011/04/21/wet-paint/#comments</comments>
		<pubDate>Thu, 21 Apr 2011 10:09:08 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=4025</guid>
		<description><![CDATA[Test drive of blog's upcoming theme.]]></description>
			<content:encoded><![CDATA[<p>I know the theme is still far from being finished and there&#8217;s still a lot to do, but I have to publish it to test server stress, ads placements, and so on.</p>
<p>Any feedback is welcome, anyway&#8230; don&#8217;t forget I will release the final theme for free so if you have suggestions or weird requests, don&#8217;t hesitate.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/04/21/wet-paint/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The new theme &#8211; first screenshot</title>
		<link>http://www.emanueleferonato.com/2011/04/12/the-new-theme-first-screenshot/</link>
		<comments>http://www.emanueleferonato.com/2011/04/12/the-new-theme-first-screenshot/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 09:49:36 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3988</guid>
		<description><![CDATA[The first screenshot of my upcoming theme to redesign this blog.]]></description>
			<content:encoded><![CDATA[<p>I just want to share with you the new theme I am designing for the blog. As said it&#8217;s heavily inspired by <a href="http://active.tutsplus.com/" target ="_blank">tutsplus</a> network, and I need some feedback.</p>
<p>Look at this screenshot:</p>
<p><img src="/wp-content/uploads/2011/04/wpscreen.jpg" /></p>
<p>Suggestions are welcome, since obviously once finished the theme will be released for free after a series of tutorials.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/04/12/the-new-theme-first-screenshot/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Executing php inside a WordPress widget without any plugin</title>
		<link>http://www.emanueleferonato.com/2011/04/11/executing-php-inside-a-wordpress-widget-without-any-plugin/</link>
		<comments>http://www.emanueleferonato.com/2011/04/11/executing-php-inside-a-wordpress-widget-without-any-plugin/#comments</comments>
		<pubDate>Mon, 11 Apr 2011 09:16:10 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3976</guid>
		<description><![CDATA[A quick snippet of code to allow Text widgets to execute php code without using any plugin.]]></description>
			<content:encoded><![CDATA[<p>Sometimes in your WordPress theme you need to execute custom php code in a widget, because you want to display different information according to the category you are in, or simply because you need to execute a php script into that widget.</p>
<p>There are a lot of plugins doing this task, adding a new type of widget generally called &#8220;php widget&#8221;, but rather than installing a plugin this simple job can be done simply adding in <code>functions.php</code> file of your theme these few lines:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'widget_text'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'execute_php'</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> execute_php<span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$html</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;&lt;&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;?php&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">!==</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
          <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #990000;">eval</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;?&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$html</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000088;">$html</span><span style="color: #339933;">=</span><span style="color: #990000;">ob_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">return</span> <span style="color: #000088;">$html</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Which will turn the default Text widget into a php enabled widget.</p>
<p>Adding this feature directly to <code>functions.php</code> allows you to create a theme with this built in feature without the need of an external plugin. This is very useful when you plan to distribute your theme.</p>
<p>Let&#8217;s see how does it work:<span id="more-3976"></span></p>
<p><strong>Line 1</strong>: <code>add_filter</code> hooks a function to a specific filter action.</p>
<p>Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. </p>
<p>The first parameter is the name of the filter to hook (<code>widget_text</code>) while te second is the name of the function to be called when the filter is applied (<code>execute_php</code>). The third is the priority, and 100 should grant us a very low priority since lower numbers correspond with earlier execution, and the default value is 10.</p>
<p>widget_text is the filter applied to the widget text of the WordPress Text widget.</p>
<p>So in the end we are telling WordPress to run <code>execute_php</code> function when the content of the text widget is generated.</p>
<p><strong>Line 2</strong>: exexute_php function. Note the argument, the HTML generated by the Text widget.</p>
<p><strong>Line 3</strong>: looking for <code>&lt;?php</code> substring inside the HTML. If we find this substring, it means there is php to be executed inside the widget.</p>
<p>If you wonder why I am looking for <code>"&lt;"."?php"</code> rather than <code>"&lt;?php"</code>, it&#8217;s just to preserve the correct syntax highlighting in most editors.</p>
<p><strong>Line 4</strong>: <code>ob_start()</code> turns output buffering on. While output buffering is active no output is sent from the script, instead the output is stored in an internal buffer. This means the HTML produced by the Text widget is temporarily saved into an internal buffer.</p>
<p><strong>Line 5 </strong>: at this time we need to evaluate the HTML as if it was a php script. <code>eval</code> function does the job, but we need to add <code>&lt;></code> to the HTML (again, split in two to avoid highlight issues) because we must tell <code>eval</code> function the php could not start from the beginning of the HTML string.</p>
<p>An example: if my Text widget contains</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>everything will work fine because the Text starts with php. But in this case:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">your IP: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REMOTE_ADDR'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><code>eval</code> function will fail because everything before <code>&lt;?php</code> is parsed as php, returning an error. That&#8217;s why the text is changed to</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">?&gt;a value: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>to tell eval we don&#8217;t start with php code.</p>
<p><strong>Lines 6 and 7</strong>: once the php has been processed, we need to save the output buffer content, clean the output buffer and turn off output buffering.</p>
<p>Finally at <strong>line 9</strong> the HTML is returned, with the php correctly parsed.</p>
<p>And that&#8217;s all, without needing any plugin.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/04/11/executing-php-inside-a-wordpress-widget-without-any-plugin/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Redesigning the blog</title>
		<link>http://www.emanueleferonato.com/2011/04/04/redesigning-the-blog/</link>
		<comments>http://www.emanueleferonato.com/2011/04/04/redesigning-the-blog/#comments</comments>
		<pubDate>Mon, 04 Apr 2011 20:48:40 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Users contributions]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3955</guid>
		<description><![CDATA[Since the blog is almost five years old, I must seriously redesign it. The problem is: there are so many beautiful blog themes out there I really do not know how to redesign my blog. That&#8217;s why I am asking you some suggestions. How should this blog look like? Which features would you add? Help [...]]]></description>
			<content:encoded><![CDATA[<p>Since the blog is almost <strong>five years old</strong>, I must seriously redesign it. The problem is: there are so many beautiful blog themes out there I really do not know how to redesign my blog.</p>
<p>That&#8217;s why I am asking you some suggestions. How should this blog look like? Which features would you add?</p>
<p>Help me with your ideas and feedback and I&#8217;ll design the blog according to your suggestions, obviously publishing the source code as usual.</p>
<p>I have to say I don&#8217;t like that much the blogs with slideshows in the header, preferring minimalist design like <a target = "_blank" href="http://psd.tutsplus.com/">tutsplus network</a>.</p>
<p>Well, I will wait for some suggestions, I&#8217;d start from the header. Consider I want to keep the logo.</p>
<p>WordPress heroes, this is your time. Show me your ultimate theme.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/04/04/redesigning-the-blog/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Triqui MochiAds plugin fixed to 1.3</title>
		<link>http://www.emanueleferonato.com/2011/01/22/triqui-mochiads-plugin-fixed-to-1-3/</link>
		<comments>http://www.emanueleferonato.com/2011/01/22/triqui-mochiads-plugin-fixed-to-1-3/#comments</comments>
		<pubDate>Fri, 21 Jan 2011 23:35:54 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3714</guid>
		<description><![CDATA[As promised, here I am with the Triqui MochiAds Arcade plugin for WordPress fixed to start feeding again. The problem is Mochi guys added a new field called &#8220;languages&#8221; that wasn&#8217;t supported by the database table. I hope you will keep on using the plugin, and I want to inform you I am writing the [...]]]></description>
			<content:encoded><![CDATA[<p>As promised, here I am with the <a href="http://www.emanueleferonato.com/triqui-mochiads-arcade-plugin-for-wordpress-official-page/">Triqui MochiAds Arcade plugin for WordPress</a> fixed to start feeding again.</p>
<p>The problem is Mochi guys added a new field called &#8220;languages&#8221; that wasn&#8217;t supported by the database table.</p>
<p>I hope you will keep on using the plugin, and I want to inform you I am writing the 2.0 version, with the capability to feed games from big portals such as Kongregate and Newgrounds.</p>
<p>If you have a wish list, this is the time to add your most wanted feature.</p>
<p>Also, I would like to post on my <a href="http://www.facebook.com/pages/Emanuele-Feronato/50374255154" target = "_blank">Facebook fan page</a> an album with all sites using the plugin or the theme, so if you want to see your site featured, send me a screenshot at info[at]emanueleferonato.com</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2011/01/22/triqui-mochiads-plugin-fixed-to-1-3/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Create a contact page in WordPress 3.0</title>
		<link>http://www.emanueleferonato.com/2010/07/01/create-a-contact-page-in-wordpress-3-0/</link>
		<comments>http://www.emanueleferonato.com/2010/07/01/create-a-contact-page-in-wordpress-3-0/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 08:40:27 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3076</guid>
		<description><![CDATA[We know there are hundreds of plugins to let you host a contact form in WordPress, but I am going to show you how to create your own one. We are about to create a custom contact page that will work under WP 3.0, and more precisely with Twenty Ten theme. Obviously, with some minor [...]]]></description>
			<content:encoded><![CDATA[<p>We know there are hundreds of plugins to let you host a contact form in WordPress, but I am going to show you how to create your own one.</p>
<p>We are about to create a custom contact page that will work under WP 3.0, and more precisely with Twenty Ten theme. Obviously, with some minor changes you will be able to do the same in your theme.</p>
<p><strong>The script</strong></p>
<p>Let&#8217;s start: in your theme folder, create a new file called <code>contact.php</code> (or whatever other name with <code>php</code> extension) and write this code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Template Name: Contact me
*/</span>
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>sent<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$error</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>your_name<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Please enter your name&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">filter_var</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>your_email<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>FILTER_VALIDATE_EMAIL<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Please enter a valid email address&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>                        
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>your_message<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$error</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;p&gt;Please enter a message&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;admin_email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>your_name<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; sent you a message from &quot;</span><span style="color: #339933;">.</span>get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;blogname&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>your_message<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;From: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>your_name<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot; &lt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>your_email<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&gt;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>Reply-To:&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>your_email<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=&quot;container&quot;&gt;
	&lt;div id=&quot;content&quot; role=&quot;main&quot;&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;div id=&quot;post-<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; <span style="color: #000000; font-weight: bold;">&lt;?php</span> post_class<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;	
			&lt;h1 class=&quot;entry-title&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
			&lt;div class=&quot;entry-content&quot;&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
				&lt;p&gt;&lt;strong&gt;Message succesfully sent. I'll reply as soon as I can&lt;/strong&gt;&lt;/p&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
				&lt;p&gt;&lt;strong&gt;Your messange hasn't been sent&lt;/strong&gt;&lt;p&gt;
				<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$error</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
				&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; id=&quot;contact_me&quot; method=&quot;post&quot;&gt;
					&lt;input type=&quot;hidden&quot; name=&quot;sent&quot; id=&quot;sent&quot; value=&quot;1&quot; /&gt;
					&lt;ul class=&quot;contactform&quot;&gt;
						&lt;li&gt;
							&lt;label for=&quot;your_name&quot;&gt;Name&lt;/label&gt;
							&lt;input type=&quot;text&quot; name=&quot;your_name&quot; id=&quot;your_name&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>your_name<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
						&lt;/li&gt;
						&lt;li&gt;
							&lt;label for=&quot;your_email&quot;&gt;Email&lt;/label&gt;
							&lt;input type=&quot;text&quot; name=&quot;your_email&quot; id=&quot;your_email&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>your_email<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
						&lt;/li&gt;
						&lt;li&gt;
							&lt;label for=&quot;your_message&quot;&gt;Message:&lt;/label&gt;
							&lt;textarea name=&quot;your_message&quot; id=&quot;your_message&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span>your_message<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/textarea&gt;
						&lt;/li&gt;
						&lt;li&gt;
							&lt;input type=&quot;submit&quot; name = &quot;send&quot; value = &quot;Send email&quot; /&gt;
						&lt;/li&gt;
					&lt;/ul&gt;
				&lt;/form&gt;
				<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;/div&gt;&lt;!-- .entry-content --&gt;
		&lt;/div&gt;&lt;!-- #post-## --&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;/div&gt;&lt;!-- #content --&gt;
&lt;/div&gt;&lt;!-- #container --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Now let&#8217;s see what we&#8217;ve done:<span id="more-3076"></span></p>
<p><strong>Lines 2-4</strong>: This is the way we assign a template name to the page. In this case, the name is <code>Contact me</code></p>
<p>We&#8217;ll see later what <strong>lines 5-19</strong> do, and let&#8217;s jump to&#8230;</p>
<p><strong>Lines 21-27</strong>: this is the same content you can find in <code>page.php</code> file into Twenty Ten theme folder, and if you&#8217;re using a different theme it should be the same content you can find in your theme <code>page.php</code> file until the beginning of the content of the page (typically <code>the_content()</code>).</p>
<p>In my case, I just replaced</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_front_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;h2 class=&quot;entry-title&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h2&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>	
	&lt;h1 class=&quot;entry-title&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>with</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;h1 class=&quot;entry-title&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;</pre></div></div>

<p>because I know a contact page can&#8217;t be the front page.</p>
<p><strong>Lines 28-33</strong>: Here come to play two variables, called <code>$error</code> and <code>$email</code>, you&#8217;ll see later how to set their values, meanwhile you have to know <code>$error</code> is an empty string or a string with an error (something like &#8220;You email address is not valid&#8221;) and <code>$email</code> is <code>true</code> if the email has been successfully sent.</p>
<p>The code proceeds this way:</p>
<p>* If the email has been sent, show a &#8220;Thank you message&#8221; and nothing else</p>
<p>* If the email has not been sent and there is an error, show the error and the form</p>
<p>* If the email has not been sent and there isn&#8217;t an error, show the page content (something like &#8220;Hello!! This is my fancy contact page!! Drop me a mail!!) and the form</p>
<p><strong>Lines 34-53</strong>: The form itself, the easiest possible, it&#8217;s up to you to add some more fields, if needed, and some styling.</p>
<p><strong>Lines 55-61</strong>: The end of the page, like in the normal Twenty Ten page.</p>
<p>Now it&#8217;s time to see the php that handles emails and errors</p>
<p><strong>Line 5</strong>: If &#8220;Send email&#8221; button (<strong>line 50</strong>) has been pressed&#8230;</p>
<p><strong>Line 6</strong>: set <code>$error</code> variable to empty string</p>
<p><strong>Lines 7-9</strong>: creating an error message if the user did not enter his name</p>
<p><strong>Lines 10-12</strong>: same as before, looking for a valid email address</p>
<p><strong>Lines 13-15</strong>: same as before, looking for a message</p>
<p><strong>Lines 16-18</strong>: if I did not find any error, I send the email with a basic formatting and sanitizing.</p>
<p><strong>The setup</strong></p>
<p>Once you created this file, create a new page this way:</p>
<p><img src="/wp-content/uploads/2010/07/pagetemplate.png" /></p>
<p>Look how I assign the page template according to the file recently created.</p>
<p>And this is what you&#8217;ll get:</p>
<p><img src="/wp-content/uploads/2010/07/result.png" /></p>
<p>Your own custom contact page. It&#8217;s just a basic one, but if I receive good feedback, I can improve it with some jQuery magic&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/07/01/create-a-contact-page-in-wordpress-3-0/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>WordPress 3.0 &#8220;Thelonious&#8221; released</title>
		<link>http://www.emanueleferonato.com/2010/06/18/wordpress-3-0-thelonious-released/</link>
		<comments>http://www.emanueleferonato.com/2010/06/18/wordpress-3-0-thelonious-released/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 08:51:20 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=3044</guid>
		<description><![CDATA[WordPress new major release is here!!! Named Thelonious after the american jazz composer Thelonious Sphere Monk (October 10, 1917 – February 17, 1982), will represent a revolution in WP community. Major new features in this release include: a sexy new default theme called Twenty Ten Short links support Custom backgrounds Custom headers Custom shortlinks Custom [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress new major release is here!!!</p>
<p>Named <strong>Thelonious</strong> after the american jazz composer Thelonious Sphere Monk (October 10, 1917 – February 17, 1982), will represent a revolution in WP community.</p>
<p>Major new features in this release include:</p>
<ul>
<li>a sexy new default theme called <strong>Twenty Ten</strong></li>
<li>Short links support</li>
<li>Custom backgrounds</li>
<li>Custom headers</li>
<li>Custom shortlinks</li>
<li>Custom menus</li>
<li>Custom post types</li>
<li>Custom taxonomies</li>
<li>Multi users support</li>
<li>Contextual help in admin area</li>
</ul>
<p>And obviously&#8230; it works with <a href="http://www.emanueleferonato.com/triqui-mochiads-arcade-theme-for-wordpress-official-page/">Triqui MochiAds arcade theme</a> and <a href="http://www.emanueleferonato.com/triqui-mochiads-arcade-plugin-for-wordpress-official-page/">plugin</a>.</p>
<p>Now it&#8217;s time to dive into theme development!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/06/18/wordpress-3-0-thelonious-released/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to list all WordPress posts with the same custom field value</title>
		<link>http://www.emanueleferonato.com/2010/05/29/how-to-list-all-wordpress-posts-with-the-same-custom-field-value/</link>
		<comments>http://www.emanueleferonato.com/2010/05/29/how-to-list-all-wordpress-posts-with-the-same-custom-field-value/#comments</comments>
		<pubDate>Fri, 28 May 2010 22:16:02 +0000</pubDate>
		<dc:creator>Emanuele Feronato</dc:creator>
				<category><![CDATA[Php]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.emanueleferonato.com/?p=2972</guid>
		<description><![CDATA[When I celebrated my four years of blogging I also introduced a big problem this blog is facing: there is so much content it&#8217;s not easy to find what you are looking for. I received some interesting suggestions, and one of them is to link all posts of the same series. This is what a [...]]]></description>
			<content:encoded><![CDATA[<p>When I celebrated my <a href="http://www.emanueleferonato.com/2010/05/26/four-years-of-blogging/">four years of blogging</a> I also introduced a big problem this blog is facing: there is so much content it&#8217;s not easy to find what you are looking for.</p>
<p>I received some interesting suggestions, and one of them is to link all posts of the same series. This is what a reader said: &#8220;In the first post, put a link of all the steps (requires manual editing)&#8221;.</p>
<p>I found a way to put an index on each post of a series using custom fields, and I am sure you&#8217;ll find it interesting. Let&#8217;s take <a href="http://www.emanueleferonato.com/2010/05/10/create-a-flash-game-like-rebuild-chile/">Create a Flash game like Rebuild Chile</a> series as example.</p>
<p>I want, in every post of the series, to show the full list of posts of the series. Without a lot of manual editing, of course.</p>
<p>So, that&#8217;s what I did: first, for every post of the series, I added a custom field called <code>series</code> with <code>Create a Flash game like Rebuild Chile</code> value. The idea is to add a <code>series</code> custom field to every post in every series with a proper value.</p>
<p>If you don&#8217;t know how to add a custom field, here it is a little help:</p>
<p><img src="/wp-content/uploads/2010/05/series.jpg" /></p>
<p>At the end of the Post page admin, you&#8217;ll find the form to add new custom fields. That&#8217;s how I added <code>series</code> custom field. Now, a few lines of code to rule them all&#8230; this is what you have to include somewhere inside the so-called <a href="http://codex.wordpress.org/The_Loop" target="_blank">WordPress Loop</a>:<span id="more-2972"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$series</span> <span style="color: #339933;">=</span> get_post_meta<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'series'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$series</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;div id = &quot;series&quot;&gt;
		&lt;h2&gt;Read all &lt;em&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$series</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/em&gt; series&lt;/h2&gt;
		&lt;ul&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$chapters</span> <span style="color: #339933;">=</span> get_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'numberposts=-1&amp;meta_key=series&amp;orderby=date&amp;order=ASC&amp;meta_value='</span><span style="color: #339933;">.</span><span style="color: #000088;">$series</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chapters</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$chapter</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
			&lt;li&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$chapter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span> <span style="color: #339933;">!=</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;a href =&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$chapter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$chapter</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/li&gt;
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;/ul&gt;
	&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>Line 1</strong>: Assigning to a variable called <code>$series</code> the value of the <code>series</code> custom field value, if any. Then, if there is a value&#8230;</p>
<p><strong>Line 5</strong>: Creating a <code>$chapters</code> array and populating it with every post (numberpost=-1) whose <code>series</code> custom field (meta_key=series) has <code>$series</code> value (meta_value=$series) ordering them by date (orderby=date) in ascending way (order=ASC). Then scanning the entire array, saving each item into <code>$chapter</code><br />
variable.</p>
<p><strong>Line 6</strong>: Adding the post title, along with a link if it&#8217;s not the current post</p>
<p>The remaining lines are just HTML to let me style the content.</p>
<p>You can see the result in the <a href="http://www.emanueleferonato.com/2010/05/10/create-a-flash-game-like-rebuild-chile/">Create a Flash game like Rebuild Chile</a> series&#8230; I have to find the right style but I think I&#8217;m on the right way.</p>
<p>Do you like this way to use custom fields?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.emanueleferonato.com/2010/05/29/how-to-list-all-wordpress-posts-with-the-same-custom-field-value/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 10/18 queries in 0.018 seconds using disk: basic

Served from: www.emanueleferonato.com @ 2012-02-08 19:59:37 -->
