<?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>Fahlstad Design &#187; Tutorials</title>
	<atom:link href="http://fahlstad.se/category/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://fahlstad.se</link>
	<description>WordPress Unlimited</description>
	<lastBuildDate>Wed, 20 Jul 2011 22:11:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Rounded corners with jquery</title>
		<link>http://fahlstad.se/2008/10/rounded-corners-with-jquery/</link>
		<comments>http://fahlstad.se/2008/10/rounded-corners-with-jquery/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 21:37:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Webdesign]]></category>

		<guid isPermaLink="false">http://www.fahlstad.se/?p=680</guid>
		<description><![CDATA[Everybody loves rounded corners in a web page but it&#8217;s a hassle to accomplish, multiple divs and different images aligned in the corret way. I&#8217; gonna show you how to do it with just a couple lines of javascript using the jquery framework. First go grab a copy of the jquery framework and the jquery.borders.js [...]]]></description>
			<content:encoded><![CDATA[<p>Everybody loves rounded corners in a web page but it&#8217;s a hassle to accomplish, multiple divs and different images aligned in the corret way. I&#8217; gonna show you how to do it with just a couple lines of javascript using the <a href="http://www.jquery.com">jquery </a>framework.<span id="more-680"></span></p>
<p>First go grab a copy of the jquery framework and the <a href="http://www.methvin.com/jquery/jquery.corner.js">jquery.borders.js</a> plugin.</p>
<p>Let&#8217;s go and create an index.html file and add some basic markup and text to it.  A div containing some text and a single paragraph. The &#8220;rounded&#8221; div is the one we are going to apply the rounded corners to.</p>
<pre lang="HTML4STRICT" line="1">
<body>
<div id="rounded" style="background:#ccc;">

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

</div>

</body>
</pre>
<p>The style is just to make the div visible.<br />
It should look like this:</p>
<div id="rounded" style="background:#ccc;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
<p>Next add the javascript files to the header between the head tags. Make sure the src is set to the path of the js files.</p>
<pre lang="HTML4STRICT" line="1">
<head>
	<script type="text/javascript" src="jquery.js "></script>
	<script type="text/javascript" src="jquery.corner.js "></script>
</head>
</pre>
<p>Now let&#8217;s add the javascript code that actually make the corners rounded. Just below the javascript src files in the header we add:</p>
<pre lang="HTML4STRICT" line="1">
<script type="text/javascript">
	$(function(){
		$("#rounded").corner();
	});
</script>
</pre>
<p>Now it should look like this:</p>
<p><img class="noborder" src="http://www.fahlstad.se/wp-content/uploads/picture-31.png" /></p>
<p>Complete code listing.</p>
<pre lang="HTML4STRICT" line="1">
// Doctype etc
<html>
<head>
	<script type="text/javascript" src="jquery.js "></script>
	<script type="text/javascript" src="jquery.corner.js "></script>
<script type="text/javascript">
	$(function(){
		$("#rounded").corner();
	});
</script>
</head>
<body>
<div id="rounded" style="background:#ccc;">

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

</div>

</body>
</html>
</pre>
<p>Yupp, thats all. Easy isn&#8217;t it? You can specify the corner style and radius in the corner call. For example:</p>
<pre lang="HTML4STRICT" line="1">
$("#rounded").corner("10px"); // 10px radius
$("#rounded").corner("tl tr 10px"); // Rounds top left and top right 10px
</pre>
<p>There&#8217;s loads more of styles, take a look at the <a href="http://www.methvin.com/jquery/jq-corner-demo.html">demo</a> page.</p>
<p>Have fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://fahlstad.se/2008/10/rounded-corners-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sidenotes with commenting &#8211; a tutorial</title>
		<link>http://fahlstad.se/2006/11/sidenotes-with-commenting-a-tutorial/</link>
		<comments>http://fahlstad.se/2006/11/sidenotes-with-commenting-a-tutorial/#comments</comments>
		<pubDate>Wed, 15 Nov 2006 12:47:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.fahlstad.se/2006/11/15/sidenotes-with-commenting-a-tutorial/</guid>
		<description><![CDATA[As i re-designed this site I made the decision to remove the fQuick plugin sidenotes in the sidebar. fQuick do not allow commenting on the links and I felt like having the opportunity to get some reader feedback on those. As it now seems many of you would like to have this too. Here is [...]]]></description>
			<content:encoded><![CDATA[<p>As i re-designed this site I made the decision to remove the fQuick plugin sidenotes in the sidebar. fQuick do not allow commenting on the links and I felt like having the opportunity to get some reader feedback on those. As it now seems many of you would like to have this too. Here is a small tutorial how I made it.<br />
<span id="more-457"></span><br />
I set up a <a href="http://www.wordpress.org">WordPress</a> category called sidenotes to be used only for this purpose, I alse noted the <em>id</em> of this category for use later. So new sidenotes is posted to this category only. I don&#8217;t want the sidenotes to show up in the main blog listing on the front page so I excluded this category like this.</p>
<pre lang="php" line="1">
// The loop
<?php if (have_posts()) :
while (have_posts()) : the_post(); ?>
		// Print the post if not in sidenotes category
		<?php if(!in_category(15)):?> // The category id noted earlier
			// code...
		<?php endif;?>
	<?php endwhile;?>
<?php endif;?>'
</pre>
<p>In the sidebar we only want the sidenotes category so we need to modify the loop here too.</p>
<pre lang="php" line="1">
// Rewind the loop so it can be used again
<?php rewind_posts();?>
// The loop again
<?php if (have_posts()) :
	while (have_posts()) : the_post(); ?>
		// Print the post if in the sidenotes category
		<?php if(in_category(15)):?> // The category id noted earlier
			// code...
		<?php endif;?>
	<?php endwhile;?>
<?php endif;?>
</pre>
<p>To get the post heading linked to the site of the sidenote is a little bit more complicated. In every sidenote post I define the url within [url]www.site.com[/url]. To extract those links we need a little regular expressions.</p>
<pre lang="php" line="1">
preg_match('|[url](.*?)[/url]|ims', $post->post_content, $m);</pre>
<p>Add this in the sidebar loop. The link can then be accessed like this: </p>
<pre lang="php" line="1">
<a href="<?php echo $m[1];?>"><?php the_title();?></a>
</pre>
<p>The complete sidebar loop would be something like this.</p>
<pre lang="php" line="1">
// Rewind the loop so it can be used again
<?php rewind_posts();?>
// The loop again
<?php if (have_posts()) :
	while (have_posts()) : the_post(); ?>
		// Print the post if in the sidenotes category
		<?php if(in_category(15)):?> // The category id noted earlier
			// Exctract the link.
			preg_match('|[url](.*?)[/url]|ims',$post->post_content,$m);
			<a href="<?php echo $m[1];?>"><?php the_title();?></a>
			<?php the_content();?>
			<?php comment_popup_link('0 commens',1 comment,'% comments','na');
		<?php endif;?>
	<?php endwhile;?>
<?php endif;?></pre>
<p>A typical sidenotes post look like this.</p>
<blockquote><p>[url]http://www.andydenton.com/2006/11/05/the-top-55-web-designers-in-the-world/[/url]<br />
According to this site I&#8217;m number 19 of the top 55 web designers in the world. Flush&#8230;</p></blockquote>
<p>Now we have sidenotes with the same functionallity as a regular blog post. This way of doing this is much like <a href="http://codex.wordpress.org/Adding_Asides#Asides_With_a_Plug-In">Asides</a>, but I prefer doing things myself. By the way I imported all my fQuick sidenotes into this new category but that&#8217;s a different story and I leave that part to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://fahlstad.se/2006/11/sidenotes-with-commenting-a-tutorial/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>LiveSearch with Prototype.js</title>
		<link>http://fahlstad.se/2006/10/livesearch-with-prototypejs/</link>
		<comments>http://fahlstad.se/2006/10/livesearch-with-prototypejs/#comments</comments>
		<pubDate>Fri, 27 Oct 2006 18:17:36 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.fahlstad.se/2006/10/27/wp-livesearch-with-prototypejs/</guid>
		<description><![CDATA[LiveSearch is a feature on many blogs these days, available as WordPress plugins or for implementation on non WordPress sites. It&#8217;s a cool feature but how does it work, and can we customize it? Of course we can. To continue tha Ajax tutorials which was started with this simple one we now continue with a [...]]]></description>
			<content:encoded><![CDATA[<p>LiveSearch is a feature on many blogs these days, available as WordPress plugins or for implementation on non WordPress sites. It&#8217;s a cool feature but how does it work, and can we customize it? Of course we can. </p>
<p>To continue tha Ajax tutorials which was started with this <a href="http://www.fahlstad.se/2006/10/20/ajax-tutorial/">simple one</a> we now continue with a slight more complicated one.<br />
<span id="more-426"></span><br />
For you who don&#8217;t know what Livesearch is we start with a small description. LiveSearch is a search function on wep pages allowing the visitor to search and the result is presented in &#8220;real time&#8221;, either as an animated drop down box or perhaps the search form is filled with the results and the visitior get the feeling it all happens &#8220;live&#8221;. An example can be seen by searching this site. The benefit with this is not only the cool feature but also a smaller bandwith usage as the whole page does not require reloading. </p>
<p>One drawback is that we need some javascript framework to be included on the pages which can be quite large at timesdepending on witch features are beeing used. For simpicity we are going to use the <a href="http://prototype.conio.net/">prototype</a> and <a href="http://script.aculo.us/">scriptaculous</a> frame work. This can be achieved without these framworks too but it requiers more code, and besides we don&#8217;t need to invent the wheel again.</p>
<p>Besides the framwork we need three file for this to work:</p>
<ul>
<li>livesearch.php<br />The file is the main search file from where the Ajax call is made.</li>
<li>general.js<br />Our javascript file which implement the features from the prototype framework</li>
<li>results.php<br />The external file called by with Ajax and are responsible for the database search.</li>
</ul>
<p>To make it clear how the program flow goes we can illustrate this with simple chart.<br />
<img id="image430" src="http://www.fahlstad.se/wp-content/pics/2006/10/ajax.png" alt="ajax.png" class="center" /><br />
Let&#8217;t start with the livessearch.php file. This is mainly a search form from where the search term is passed to the functions in general.js.</p>
<p><cite>livesearch.php</cite></p>
<pre lang="html4strict" line="1">
<html>
<head>

  <script type="text/javascript" src="general.js" />
  <script type="text/javascript" src="scriptaculous.js?load=effects" />
  <script type="text/javascript" src="prototype.js" />
</head>
<body>
<form method="get" action="" id="searchform">
<input type="text" id="search_term" />
<input type="submit" id="search_button />
  </form>
<div id="searchresults"></div>

</body>
</html>
</pre>
<p>That's all there is to it, the id's on the form, text and button is important because these are used by the javascript during the Ajax call. The div with the id="searchresults" is where the response from the Ajax call is to displayed.</p>
<p>No let's move on to general.js, this is where the meat is, at least for the client side.<br />
<cite>general.js</cite></p>
<pre lang="javascript" line="1">
function init(){
$('searchform').onsubmit = function() { doSearch();return false; };
}
function doSearch(){
new Ajax.Updater('searchresults', 'results.php?s=' + $('search_term').value,
    {onComplete:function(){ new Effect.Highlight('searchresults');},
    asynchronous:true});
}
Event.observe(window, 'load', init, false);
</pre>
<p>Lets go through the code line by line. On line 7 we put an onSubmit observer on the form in livesearch.php. This means that whenever the form is submitted the function doSearch is called by the observer. As you can see we are using the function $('searchform').onsubmit to do this. $(id) is a prototype function which returns the element with the id of the parameter. Quite handy. Normally we would do document.getElementById(id).onsubmit which is the same thing but less elegant.</p>
<p>Line 1 the init function is called automaic from line 8 when the page loads. So, when the search form is submitted the doSearch function is called and here the Ajax request is made to the results.php with ?s= as get variable. The Ajax.Updater has an additional option here and that is the Effects.Highlight and this is only eye candy. It makes the updated div searchresults flash once when the request is finished. There are several more effects like this in the prototype framework but that's besides the point. </p>
<p>Now, when the Ajax request is finished the searchresults div is updated like magic with the results from results.php. Results.php looks like this:<br />
<cite>results.php</cite></p>
<pre lang="php" line="1">
// Get the search term
$searchtearm = $_GET['s'];

// Connect to db
$conn = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$conn) {
  die('Not connected : ' . mysql_error());
}

// make foo the current db
$db_selected = mysql_select_db('foo', $conn);
if (!$db_selected) {
  die ('Can't use foo : ' . mysql_error());
}

// Get the search results
$res = mysql_query('SELECT * FROM table WHERE value = $searchterm');

// Echo the results
foreach.(..){
  ...
}
mysql_close($link);
</pre>
<p>I will not explain the PHP code for the results.php since this should be quite obvious. Besides the code is not complete it merley shows the outline. But it should get you started with Ajax.</p>
<p>That's all there is to it, now go home and try this for your self. Good luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://fahlstad.se/2006/10/livesearch-with-prototypejs/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Ajax tutorial</title>
		<link>http://fahlstad.se/2006/10/ajax-tutorial/</link>
		<comments>http://fahlstad.se/2006/10/ajax-tutorial/#comments</comments>
		<pubDate>Fri, 20 Oct 2006 21:38:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.fahlstad.se/2006/10/20/ajax-tutorial/</guid>
		<description><![CDATA[This tutorial is intended to give the reader some initial understanding of the power of using Ajax as a tool on a web page. The web pages are growing larger and larger due to more and more bandwidth around the globe. This is nice since the web is getting more readable and more visual appealing. [...]]]></description>
			<content:encoded><![CDATA[<p>This tutorial is intended to give the reader some initial understanding of the power of using Ajax as a tool on a web page. The web pages are growing larger and larger due to more and more bandwidth around the globe. </p>
<p>This is nice since the web is getting more readable and more visual appealing. But if your web host have a traffic limit per day the size of the total files requested by each visitor becomes critical, at least if you have many visitors.<br />
<span id="more-425"></span><br />
Ajax is a way to update a part of a web page without the nessisity to reload the whole page. This can save you a lot of bandwidth, if used wisely. So we are going to create a simple html page with dynamic content. We are going to use the prototype framework which is a javascript framefork for a numerous action, including Ajax calls. So start by downloading <a href="http://prototype.conio.net/">prototype.js</a> and <a href="http://script.aculo.us/downloads">script.aculo.us</a>. Place all the files on your server.</p>
<p>For this tutorial we are going to create three files:</p>
<ul>
<li>index.html</li>
<li>tutorial.js</li>
<li>page.html</li>
</ul>
<p>Let&#8217;s start with the markup<br />
<cite>index.html</cite></p>
<pre class="brush: php; title: ; notranslate">&lt;html&gt;
&lt;head&gt;
&lt;script src=&quot;js/prototype.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;js/scriptaculous.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;js/tutorial.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
	&lt;h1&gt;This is a demo page using Ajax&lt;/h1&gt;
	&lt;h2&gt;Click on the link&lt;/h2&gt;
	&lt;a href=&quot;javascript:getit();&quot;&gt;Click me&lt;/a&gt;
	&lt;div id=&quot;update&quot;&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;/pre&gt;
We start by including all the nessesary javascript files, tutorial.js is our file we are about to create. All this page has is a link and a div. When the link is clicked the javacript function getit() is called and is located in tutorial.js. So let's take a look at tutorial.js.
&lt;cite&gt;tutorial.js&lt;/cite&gt;
&lt;pre lang=&quot;javascript&quot; line=&quot;1&quot;&gt;
function getit(){
	var url = &quot;page.html&quot;;
	new Ajax.Updater('update', url);
}
</pre>
<p>Small huh? Well since we are going to fetch data from another file we need to declare the file which in this case is page.html. This is the page the Ajax.Updater is fetching for us and outputs it to the &#8216;update&#8217; div without reloading the whole page. The Ajax.Updater takes two parameters which is the id of the div to be updated and an url from where we fetch our data.</p>
<p><cite>page.html</cite></p>
<pre class="brush: xml; title: ; notranslate">
&lt;ul&gt;
	&lt;li&gt;Apples&lt;/li&gt;
	&lt;li&gt;Oranges&lt;/li&gt;
	&lt;li&gt;Elephants&lt;/li&gt;
&lt;/ul&gt;
</pre>
<p>All put together there is not much code to get this working and there are endless possibilities. I&#8217;ve set up a <a href="/wp-content/tutorials/ajax/ajax.html">demo</a> where you can see the action live. Good luck.</p>
]]></content:encoded>
			<wfw:commentRss>http://fahlstad.se/2006/10/ajax-tutorial/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>WordPress theme CSS &#8211; a tutorial</title>
		<link>http://fahlstad.se/2006/06/css-a-tutorial/</link>
		<comments>http://fahlstad.se/2006/06/css-a-tutorial/#comments</comments>
		<pubDate>Mon, 26 Jun 2006 18:51:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.fahlstad.se/2006/06/26/css-a-tutorial/</guid>
		<description><![CDATA[A get a lot of questions on how to do this and that in my themes, since all my themes are css-based it get&#8217;s a little complicated to all people asking for help. The most frequent questions is &#8220;how do I get rid off the image borders?&#8221; Here is the answer: All my themes are [...]]]></description>
			<content:encoded><![CDATA[<p>A get a lot of questions on how to do this and that in my <a href="/themes">themes</a>, since all my themes are css-based it get&#8217;s a little complicated to all people asking for help.<br />
<span id="more-215"></span></p>
<p>The most frequent questions is &#8220;how do I get rid off the image borders?&#8221; Here is the answer: All my themes are based off the same template and the content and images is therefore inside a div tag with id=&#8221;content&#8221;. To get rid of the borders edit style.css look for:</p>
<pre lang="css" line="1">
#content img {
border:0;
}
</pre>
<p>border:0 means that the image in content will get no borders. If there are no borders and you like to add some, do this:</p>
<pre lang="css" line="1">
#content img{
border: 1px solid #color
}
</pre>
<p>More to come.</p>
]]></content:encoded>
			<wfw:commentRss>http://fahlstad.se/2006/06/css-a-tutorial/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Widgetize your WordPress theme &#8211; a tutorial</title>
		<link>http://fahlstad.se/2006/06/widgetize-your-wordpress-theme/</link>
		<comments>http://fahlstad.se/2006/06/widgetize-your-wordpress-theme/#comments</comments>
		<pubDate>Fri, 02 Jun 2006 07:52:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.fahlstad.se/2006/06/02/widgetize-your-wordpress-theme/</guid>
		<description><![CDATA[If you have an WordPress account in wordpress.com you have probably seen that you can manage your sidebar dynamically. For this to work the current theme has to support widgets. Autmattic has come up with a plugin to enable this feature in a regular wordpress installation. In order to widgetize your current theme all you [...]]]></description>
			<content:encoded><![CDATA[<p>If you have an <a href="htp://www.wordpress.com">WordPress</a> account in wordpress.com you have probably seen that you can manage your sidebar dynamically. For this to work the current theme has to support widgets. Autmattic has come up with a <a href="http://automattic.com/code/widgets/">plugin</a> to enable this feature in a regular wordpress installation.<br />
<span id="more-172"></span><br />
In order to widgetize your current theme all you have to do is register some functions and add a small amount of code to your sidebar.php. If you don&#8217;t have a functions.php in your theme create one and put this to it.</p>
<pre lang="php" line="1">
<?php
if ( function_exists('register_sidebar') )
    register_sidebar();
?>
</pre>
<p>This is to register the sidebar as dynamic. Save and close we are done with functions.php </p>
<p>Let&#8217;s move on to sidebar.php and take a look how a regular file would look like.</p>
<pre lang="php" line="1">
<div id="sidebar">
<h2>Search this site</h2>
<div id="searchdiv">
<form id="searchform" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="s" id="s" size="20"/>
<input name="sbutt" type="submit" value="Go" alt="Submit"  />
    </form>
</div>
<h2><?php _e('Archives'); ?></h2>
<ul><?php wp_get_archives('type=monthly'); ?></ul>
<h2><?php _e('Categories'); ?></h2>
<ul><?php list_cats() ?></ul>
<h2><?php _e('Meta'); ?></h2>
<ul>
    <?php wp_register(); ?>
<li><a href="<?php bloginfo('rss2_url'); ?>">RSS</a></li>
<li><?php wp_loginout(); ?></li>
</ul>

 <?php wp_meta(); ?>
</div>
</pre>
<p>To enable the widget support all we have to do is enclose the sidebar code in an if statement. Like this:</p>
<pre lang="php" line="1">
<div id="sidebar">
<h2>Search this site</h2>
<div id="searchdiv">
<form id="searchform" method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="s" id="s" size="20"/>
<input name="sbutt" type="submit" value="Go" alt="Submit"  />
    </form>
</div>

//-----------------------------------------------------------
  <?php if ( !function_exists('dynamic_sidebar')
        || !dynamic_sidebar() ) : ?> // added
//-----------------------------------------------------------
<h2><?php _e('Archives'); ?></h2>
<ul><?php wp_get_archives('type=monthly'); ?></ul>
<h2><?php _e('Categories'); ?></h2>
<ul><?php list_cats() ?></ul>
<h2><?php _e('Meta'); ?></h2>
<ul>
    <?php wp_register(); ?>
<li><a href="<?php bloginfo('rss2_url'); ?>">RSS</a></li>
<li><?php wp_loginout(); ?></li>
</ul>

 <?php wp_meta(); ?>
//-----------------------------------------------------------
  <?php endif; ?> // added
//-----------------------------------------------------------
</div>
</pre>
<p>If you uninstall thw widget plugin or decide not to use it the default sidebar will be shown, the code within the if statement. Now go and install the widget plugin and you are set to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://fahlstad.se/2006/06/widgetize-your-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Secrets of a WordPress plugin</title>
		<link>http://fahlstad.se/2006/04/secrets-of-wordpress-plugins/</link>
		<comments>http://fahlstad.se/2006/04/secrets-of-wordpress-plugins/#comments</comments>
		<pubDate>Mon, 03 Apr 2006 17:20:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.fahlstad.se/2006/04/03/secrets-of-wordpress-plugins/</guid>
		<description><![CDATA[A while ago I wrote a small tutorial on how a WordPress theme is created, now I would like to share some &#8220;secrets&#8221; of WordPress plugin programming, so here we go. So what kind of plugin are we going to create? Let&#8217;s do a plugin that gets some WordPress data from the database and puts [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I wrote a small <a href="http://www.fahlstad.se/2005/10/12/anatomy-of-a-wp-theme-a-tutorial/">tutorial</a> on how a WordPress theme is created, now I would like to share some &#8220;secrets&#8221; of WordPress plugin programming, so here we go.</p>
<p>So what kind of plugin are we going to create? Let&#8217;s do a plugin that gets some WordPress data from the database and puts it on a static page. shall we.<br />
<span id="more-142"></span><br />
The first thing we need to do is create a plugin file with the correct information in the header so that WordPress can identify it as a plugin. We will call this plugin wp-plugin. The normal thing to do is give the plugin file the same name as the plugin itself, hence the name for our file is wp-plugin.php. We put this file in the wp-content/plugins directory of our WordPress installation.</p>
<h4>It&#8217;s all in the head</h4>
<p>The header of wp-plugin.php contains information about plugin name, author name and author email, web site an so. The most important is the plugin name.</p>
<p>wp-plugin.php</p>
<pre lang="php" line="1">
<?php
/*
Plugin Name: wp-plugin
Plugin URI: http://www.fahlstad.se
Description: More information.
Author: Fredrik Fahlstad
Version: 1.0
Author URI: http://www.fahlstad.se
*/
?>
</pre>
<p>When the user visits the WordPress admin->plugins WordPress scans the plugins directory for plugin files so if the header is correct the file is added to the interface and can be activated or deactivated.</p>
<p>Lets take a look at the code. As you can see we have specified some meta information of the plugin, the code is self explanatory and not hard to understand. This is what WordPress uses to mark the file as a plugin as long as it&#8217;s located in the correct folder.</p>
<h4>Hooks and filters</h4>
<p>For the plugin to interact with WordPress it need some <a href="http://codex.wordpress.org/Plugin_API">API </a>to interact with so WordPress has it&#8217;s own API for plugins.</p>
<p>Hooks are provided by WordPress to allow your plugin to &#8216;hook into&#8217; the rest of WordPress. There are two kinds of hooks:<br />
Hooks that take <a href="http://codex.wordpress.org/Plugin_API#Actions">Actions</a>. Actions are functions that specify additional events that can occur triggered by core WordPress events. Action Hooks, then, enable the addition and removal of functions whose execution will be triggered by those WordPress actions. These hooks enable plugins to execute functions each time the specified event occurs.</p>
<p>Hooks that take <a href="http://codex.wordpress.org/Plugin_API#Filters">Filters</a>. Filters are functions that modify WordPress content stored in your database. Filter Hooks allow you to add or remove Filters to various types of WordPress content (usually text). These enable plugins to modify content or text on-the-fly.</p>
<p>From a coding perspective, actions and filters are nearly identical. The add_action function is nothing more than an alias for the add_filter function. In practice, they are useful for different things.</p>
<p>You can sometimes accomplish the same goal with either an action or a filter. For example, adding an action to publish_post or a filter to the_content. Choose based on whether you want the change to be made once or to be made every time the content is accessed.</p>
<h4>So lets write some code</h4>
<pre lang="php" line="1">
<?php
/*
Plugin Name: wp-plugin
Plugin URI: http://www.fahlstad.se
Description: More information.
Author: Fredrik Fahlstad
Version: 1.0
Author URI: http://www.fahlstad.se
*/
?>
<?php
/**
*   Backend function
*   Parameter: content, the content send from WordPress
*   to this function trough the add_filter below, it
*   must return the content.
*/
function my_content($content)
{
   $url= get_bloginfo('site_url');
   return preg_replace("|<!--wp-plugin-->|", $url, $content);
}

/**
*   This will be added to the header of WordPress trough the
*   add_filter below.
*/
function my_header()
{
<link rel="stylesheet" type="text/css" href="my_styles.css" />
}

/**
*   Install filter and hooks.
*   WordPress sends the content from the
*   database to the my_function above.
*/
add_filter('the_content', 'my_content');

/**
*   This will be added to the header of the WordPress
*   before it is displayed, perfect for adding your own css or scripts.
*/
add_action('wp_head','my_header')
</pre>
<p>Let&#8217;s take a look at the code above. At the end we define our hooks and filters that interact with the API. The function my_content($content) is    where it all happens. This function takes the content generated from the database such as the content of a page or a post. This is done via the API and WordPress is responsible for the content that is send to the function. In this function we retrive some trivial data from the database and puts it in a variable. </p>
<p>Now the difficult part comes. We have to replace our tag in the static page with our data from the database, and that is done with preg_replace, we simply replace our <code lang="php"><!--wp-plugin--></code> whith the content in our variable. Last we returns the content back to WordPress so it can be displayed.</p>
<p>For this to work we need to create a static page and somewhere we put our <!--wp-plugin--> tag to replace. </p>
<h4>Summary</h4>
<ul>
<li>Create a file</li>
<li>Add the header</li>
<li>Add hooks and filter</li>
<li>Create the functions</li>
<li>Replace data and return the content</li>
</ul>
<h4>Further reading</h4>
<p><a href="http://codex.wordpress.org/Main_Page">WordPress Codex</a></p>
]]></content:encoded>
			<wfw:commentRss>http://fahlstad.se/2006/04/secrets-of-wordpress-plugins/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Simple PHP template</title>
		<link>http://fahlstad.se/2006/02/simple-php-template/</link>
		<comments>http://fahlstad.se/2006/02/simple-php-template/#comments</comments>
		<pubDate>Fri, 24 Feb 2006 23:05:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.fahlstad.se/2006/02/25/simple-php-template/</guid>
		<description><![CDATA[Have you ever wondered how to create a simple PHP template for using on your web site? This tutorial will explain the concept and in the end you will see some code examples. The concept of templates is that from one simple index file we include some other file based on GET variables. If you [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever wondered how to create a simple PHP template for using on your web site? This tutorial will explain the concept and in the end you will see some code examples. The concept of templates is that from one simple index file we include some other file based on GET variables. If you don&#8217;t know what a GET variable is this tutorial may be over your head and I suggest you learn this otherwise.<br />
<span id="more-118"></span><br />
The advantage of using templates are:</p>
<ul>
<li>Easy to maintain</li>
<li>Easy to change design</li>
<li>Consistent look</li>
</ul>
<p>Here are the simplified code for index.php</p>
<pre lang="php" line="1">
<html>
<head>
// Code for including css file
...
</head>
<body>
// Code for menu etc.
<ul>
<li><a href="index.php?pages=home">home</a></li>
<li><a href="index.php?pages=work">work</a></li>
<li><a href="index.php?pages=about">about</a></li>
<li><a href="index.php?pages=portfolio">portfolio</a></li>
</ul>

<?php

     // Check if GET variable is set.
     if(isset($_GET['pages']))
     {
            // GET is set, include the proper page
            switch($_GET['pages'])
            {
                  case 'work': include("work.php");
                  case 'portfolio': include("portfolio.php");
                  case 'about': include("about.php");
                  case 'home': include("start.php");
                  // GET is set but none of the above match
                  default: include("start.php");
           }
     }
     // GET variable not set
     else
     {
           include("start.php");
     }
?>
</body>
</html>
</pre>
<p>All you need to do now is create the individual pages. If you want additional pages all you have to do is create a link in the menu and make an include statement in the switch block. The pages should only contain text and/or html, all the styling should be in a css file included in the index file.</p>
]]></content:encoded>
			<wfw:commentRss>http://fahlstad.se/2006/02/simple-php-template/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Dual boot Mac OSX86 and Win XP</title>
		<link>http://fahlstad.se/2006/01/dual-boot-mac-osx86-and-win-xp/</link>
		<comments>http://fahlstad.se/2006/01/dual-boot-mac-osx86-and-win-xp/#comments</comments>
		<pubDate>Mon, 23 Jan 2006 21:45:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.fahlstad.se/?p=111</guid>
		<description><![CDATA[In a recent article I said that there were no way to install Mac OSX on a partition but only to an empty hard drive. Well, I have found a way to install Mac Os X on a partition and dual boot Win XP. You aren&#8217;t allowed to use this guide to install OSX on [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="/2005/10/15/mac-os-x-tiger-on-x86/">recent </a>article I said that there were no way to install Mac OSX on a partition but only to an empty hard drive. Well, I have found a way to install Mac Os X on a partition and dual boot Win XP.</p>
<p>You aren&#8217;t allowed to use this guide to install OSX on your PC if you are not an Apple developer! This guide only shows you that it is possible and tells you something about partitioning! So: Buy an Apple from apple.com if you want to run osx!</p>
<ul>
<li>Partition your hard drive accordingly.</li>
<li>Download Mac OSX Tiger DVD.</li>
<li>Install Mac OSX on a partition.</li>
<li>Restart the computer with a Win 98/ME start cd or disk.</li>
<li>Start fdisk, set Win XP partition as active.</li>
<li>Copy <a href="http://www.360hacker.net/chain0.rar">chain0 </a>to c:.</li>
<li>Add chain0=&#8221;Mac OSX&#8221; to boot.ini in Win XP.</li>
<li>Restart.</li>
<li>Enjoy dual booting.</li>
</ul>
<h4>Not working</h4>
<p>Wireless connection does dot work with the Intel PRO/Wireless 2200bg card. No sound either. I have looked for a driver for the wireless card but have not found any, any suggestions?</p>
]]></content:encoded>
			<wfw:commentRss>http://fahlstad.se/2006/01/dual-boot-mac-osx86-and-win-xp/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>Beginner&#8217;s QT GUI tutorial</title>
		<link>http://fahlstad.se/2005/10/qt-tutorial/</link>
		<comments>http://fahlstad.se/2005/10/qt-tutorial/#comments</comments>
		<pubDate>Mon, 17 Oct 2005 22:10:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Stuff]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.fahlstad.se/?p=38</guid>
		<description><![CDATA[As a programmer/computer engineer I thought I should share some of my knowledge to you who are interested. In this tutorial you will learn to create a simple program with a graphical user interface. For this we will use the exelent QT which is a API from the Norwegian TrollTech who emulates the graphical API [...]]]></description>
			<content:encoded><![CDATA[<p>As a programmer/computer engineer I thought I should share some of my knowledge to you who are interested. In this tutorial you will learn to create a simple program with a graphical user interface.<br />
<span id="more-38"></span><br />
For this we will use the exelent <a href="http://www.trolltech.com">QT </a>which is a API from the Norwegian <a href="http://www.trolltech.com">TrollTech </a>who emulates the graphical API on the target machine. We will write this in Windows, but as it is designed to work between diffrent platforms we could compile the same code in Linux or whatever platform QT is available for. You can download a trial of the <a href="http://www.trolltech.com/download/qt/evaluate.html">commercial API</a> or a <a href="http://www.trolltech.com/download/qt/windows.html">free GPL licenced one</a>. If you are using Linux you can download the full <a href="http://www.trolltech.com/products/qt3/x11.html">schmeck </a>for free. If you use Windows you have to satisfy with the trial or the older GPL licenced.</p>
<p>Anyway we will create a simple Hello World program in C++, the classical program for any programmer newbie. To begin with we will create the user interface using as you can see, a very small amount of code. </p>
<pre lang="cpp" line="1">
#include <QApplication>
#include <QPushButton>
int main(int argc, char *argv[])
{
       QApplication app(argc, argv);
        QPushButton hello("Hello world!");
        hello.resize(100, 30);
        hello.show();
        return app.exec();
}
</pre>
<p>Lets go through the code line by line.</p>
<p>This line includes the QApplication class definition. There has to be exactly one QApplication object in every GUI application that uses Qt. QApplication manages various application-wide resources, such as the default font and cursor.</p>
<pre lang="cpp" line="1">
#include <QPushButton>
</pre>
<p>This line includes the QPushButton class definition. For each class that&#8217;s part of the public Qt API, there exists a header file of the same name that contains its definition.</p>
<p>QPushButton is a GUI push button that the user can press and release. It manages its own look and feel, like every other QWidget. A widget is a user interface object that can process user input and draw graphics. The programmer can change both the overall look and feel and many minor properties of it (such as color), as well as the widget&#8217;s content. A QPushButton can show either a text or a QIcon.</p>
<pre lang="cpp" line="1">
  int main(int argc, char *argv[])
</pre>
<p>The main() function is the entry point to the program. Almost always when using Qt, main() only needs to perform some kind of initialization before passing the control to the Qt library, which then tells the program about the user&#8217;s actions via events.</p>
<p>The argc parameter is the number of command-line arguments and argv is the array of command-line arguments. This is a standard C++ feature.</p>
<pre lang="cpp" line="1">
 QApplication app(argc, argv);
</pre>
<p>The app object is this program&#8217;s QApplication instance. Here it is created. We pass argc and argv to the QApplication constructor so that it can process certain standard command-line arguments (such as -display under X11). All command-line arguments recognized by Qt are removed from argv, and argc is decremented accordingly. See the QApplication::argv() documentation for details.</p>
<p>The QApplication object must be created before any GUI-related features of Qt are used.</p>
<pre lang="cpp" line="1">
QPushButton hello("Hello world!");
</pre>
<p>Here, after the QApplication, comes the first GUI-related code: A push button is created.</p>
<p>The button is set up to display the text &#8220;Hello world!&#8221;. Because we don&#8217;t specify a parent window (as second argument to the QPushButton constructor), the button will be a window of its own, with its own window frame and title bar.</p>
<pre lang="cpp" line="1">
  hello.resize(100, 30);
</pre>
<p>The button is set up to be 100 pixels wide and 30 pixels high (excluding the window frame, which is provided by the windowing system). We could call QWidget::move() to assign a specific screen position to the widget, but instead we let the windowing system choose a position.</p>
<pre lang="cpp" line="1">
 hello.show();
</pre>
<p>A widget is never visible when you create it. You must call QWidget::show() to make it visible.</p>
<pre lang="cpp" line="1">
   return app.exec();
</pre>
<p>This is where main() passes control to Qt. QCoreApplication::exec() will return when the application exits. (QCoreApplication is QApplication&#8217;s base class. It implements QApplication&#8217;s core, non-GUI functionality and can be used when developing non-GUI applications.)</p>
<p>In QCoreApplication::exec(), Qt receives and processes user and system events and passes these on to the appropriate widgets.</p>
<p>You should now try to compile and run this program.</p>
<p>The tutorial examples are located in Qt&#8217;s examples/tutorial directory. They are automatically built when you build Qt.</p>
<p>If you have typed in the source code manually, you will need to follow these instructions: To compile a C++ application, you need to create a makefile. The easiest way to create a makefile for Qt is to use the qmake build tool supplied with Qt. If you&#8217;ve saved main.cpp in its own otherwise empty directory, all you need to do is:</p>
<p>    qmake -project<br />
    qmake</p>
<p>The first command tells qmake to create a project file (a .pro file). The second command tells it to create a platform-specific makefile based on the project file. You should now be able to type make (or nmake if you&#8217;re using Visual Studio) and then run your first Qt application!</p>
<p>From <a href="http://www.trolltech.com">www.trolltech.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://fahlstad.se/2005/10/qt-tutorial/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

