<?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>WordPress Freelancer &#187; Tutorials</title>
	<atom:link href="http://www.wplancer.com/tag/tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wplancer.com</link>
	<description>WordPress Freelance Designer &#38; Developer</description>
	<lastBuildDate>Mon, 08 Feb 2010 22:33:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Easy PHP II: Variables</title>
		<link>http://www.wplancer.com/easy-php-ii-variables/</link>
		<comments>http://www.wplancer.com/easy-php-ii-variables/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 21:58:50 +0000</pubDate>
		<dc:creator>BANAGO</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.wplancer.com/?p=986</guid>
		<description><![CDATA[In the previous <a title="PHP Introductin" href="http://www.wplancer.com/easy-php-i-introduction/">introductory PHP tutorial</a> we talked about what PHP looks like and in what kind of environment it runs. To sum up, we said that we write PHP code between tags that look like this: “<em>&#60;?php … ?&#62;</em>” and we end every command line must and in semicolon (<em>;</em>). We use “<em>echo</em>” or “<em>print</em>” in order for PHP to show things to us.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 15px 10px 0 0;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.wplancer.com%2Feasy-php-ii-variables%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.wplancer.com%2Feasy-php-ii-variables%2F&amp;source=banago&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><strong><a href="http://www.wplancer.com/wp-content/tux-php-variables.jpeg"><img class="size-medium wp-image-990 alignright" title="tux-php-variables" src="http://www.wplancer.com/wp-content/tux-php-variables-249x249.jpg" alt="" width="249" height="249" /></a></strong>In the previous <a title="PHP Introductin" href="http://www.wplancer.com/easy-php-i-introduction/">introductory PHP tutorial</a> we talked about what PHP looks like and in what kind of environment it runs. To sum up, we said that we write PHP code between tags that look like this: “<em>&lt;?php … ?&gt;</em>” and we end every command line must and in semicolon (<em>;</em>). We use “<em>echo</em>” or “<em>print</em>” in order for PHP to show things to us. We also said that we need to have Apache server, PHP and MySQL installed in our computer or server so that PHP can run and we concluded that using a ready-made package like XAMPP, WAMP, or MAMP to achieve that would be optimal. Today we are going to learn about PHP variables, their kinds and use.</p>
<h3>What are Variables</h3>
<p>Here is what a variable looks like:</p>
<pre class="php">
<span class="phpScriptTag"><span class="phpOperator">&lt;</span><span class="phpOperator">?</span>php</span>
<span class="phpComment">// Our first variable
</span>
$cool_variable <span class="phpOperator">=</span> <span class="phpString">'This s a really cool variable'</span><span class="phpText">;</span>
<span class="phpScriptTag"><span class="phpOperator">?</span><span class="phpOperator">&gt;</span></span>
</pre>
<p>Variables are used to hold some value or data for a certain time so that you can use it when you need it later in your code. Variables start with a dollar sign ($).  A variable name must start with a letter or an underscore &#8220;_&#8221; .  A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z, 0-9, and _ )  and should not contain spaces. When a variable name is made of more than one word, it can be separated with an underscore ($cool_variable), or written in camel case ($coolVariable).  Variables can hold data of different types.</p>
<p><strong>PHP Variables Data Types</strong></p>
<p>There are four PHP variables data types. Let&#8217;s deduce them by example:</p>
<pre class="php">
<span class="phpScriptTag"><span class="phpOperator">&lt;</span><span class="phpOperator">?</span>php</span>
$first_type <span class="phpOperator">=</span> <span class="phpString">'This a cool text variable'</span><span class="phpText">;</span> <span class="phpComment">// Just text.
</span>
$second_type <span class="phpOperator">=</span> 123; <span class="phpComment">// Just a number – note the lack of quotes<span class="phpOperator">.</span>
</span>
$third_type <span class="phpOperator">=</span> <span class="phpNumber">1</span><span class="phpOperator">.</span>23; <span class="phpComment">// Decimal number – note the lack of quotes<span class="phpOperator">.</span>
</span>
$fourth_type <span class="phpOperator">=</span> <span class="phpString">' '</span><span class="phpText">;</span> <span class="phpComment">// Just empty  - cool, isn&#039;t it.
</span>
<span class="phpScriptTag"><span class="phpOperator">?</span><span class="phpOperator">&gt;</span></span>
</pre>
<p>As you can see in above examples, declaring any type of variable is very easy. Every type has a name and they are respectively called: 1. <strong>String</strong>, 2. <strong>Integer</strong>, 3. <strong>Float</strong>, 4. <strong>Boolean</strong>. We don&#8217;t need to tell PHP which data type is variable holding; PHP evaluates the data when you assign it to the variable and then stores it as the appropriate type. Let&#8217;s talk about them in detail.</p>
<ul>
<li><strong>String: </strong>A 	series of characters, otherwise called text. There is no practical 	limit on the length of a string or text. A string must be written 	between double or single quotes, otherwise PHP will produce an 	error.</li>
<li><strong>Integer</strong>: 	A whole number (no fractions), such as –43, 0, 1, 27, or 5438. 	Integer numbers should not be wrapped with quotes, otherwise they 	will be considered as a string, not an integer i.e. text and not 	number.</li>
<li><strong>Float</strong>: A 	number (usually not a whole number) that includes decimal places, 	such as 5.24 or 123.456789. This is often called a real number or a 	float. A float should not be wrapped with quotes too.</li>
<li><strong>Boolean</strong>: 	A TRUE or FALSE value. Boolean data types represent two possible 	states — TRUE or FALSE. A FALSE boolean is declared 	in several ways  &#8211; at the example above we saw only one of them. 	Here is the whole list:
<ul>
<li>The string 		<em>FALSE</em> (can be upper- or lowercase)</li>
<li>The integer 0</li>
<li>The float 0.0</li>
<li>An empty 		string (as in the example above)</li>
<li>The 		one-character string &#8217;0&#8242;</li>
<li>The constant 		NULL</li>
</ul>
<p>On the other hand, 	any other values in a Boolean variable are considered 	TRUE. If you echo a Boolean variable, the value FALSE displays as a 	blank string; the value TRUE echoes as a 1.</li>
</ul>
<p><strong>Assigning data to variables</strong></p>
<p>The equals sign we used in the above statements is called the <strong><em>assignment operator</em></strong>, as it is used to assign values to variables.  There are a ton other <strong><em>PHP operators</em></strong> that we need to know in order to be successful PHP programmers and we will talk about them in our next tutorial <em>PHP Operators</em>, so stay tuned.</p>
<p><strong>Further Readings:</strong></p>
<ol>
<li>Understanding 	PHP Data Types: 	<a href="http://eu.dummies.com/WileyCDA/how-to/content/understanding-php-data-types.html#ixzz0eONIuWQ5">http://eu.dummies.com/WileyCDA/how-to/content/understanding-php-data-types.html</a></li>
<li>PHP 	Variables: <a href="http://www.w3schools.com/PHP/php_variables.asp">http://www.w3schools.com/PHP/php_variables.asp</a></li>
<li>What 	is a Variable: <a href="http://www.homeandlearn.co.uk/php/php2p1.html">http://www.homeandlearn.co.uk/php/php2p1.html</a></li>
<li>Learn 	PHP from Scratch: 	<a href="http://net.tutsplus.com/tutorials/php/learn-php-from-scratch-a-training-regimen/">http://net.tutsplus.com/tutorials/php/learn-php-from-scratch-a-training-regimen/</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.wplancer.com/easy-php-ii-variables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Limit Content in WordPress</title>
		<link>http://www.wplancer.com/how-to-limit-content-in-wordpress/</link>
		<comments>http://www.wplancer.com/how-to-limit-content-in-wordpress/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 14:31:14 +0000</pubDate>
		<dc:creator>BANAGO</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.wplancer.com/?p=905</guid>
		<description><![CDATA[Have you seen those cool magazine style WordPress themes around this days? They are just cool. You might have noticed that they sometimes show a few words of the post, this is for sure not the default WordPress excerpt showing that because the default excerpt length is set to 55 words and manually excerpting every post would be a great time consumer. So, what are this guys putting together to get that cool effect on their sites by controlling the length of the content?]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 15px 10px 0 0;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.wplancer.com%2Fhow-to-limit-content-in-wordpress%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.wplancer.com%2Fhow-to-limit-content-in-wordpress%2F&amp;source=banago&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p><a href="http://www.wplancer.com/wp-content/wordpress-limit-content.png"><img class="size-medium wp-image-963 alignright" title="wordpress-limit-content" src="http://www.wplancer.com/wp-content/wordpress-limit-content-250x250.png" alt="" width="250" height="250" /></a>Have you seen those cool magazine style WordPress themes around this days? They are just cool. You might have noticed that they sometimes show a few words of the post, this is for sure not the default <a title="WordPress Excerpt" href="http://codex.wordpress.org/Template_Tags/the_excerpt">WordPress excerpt</a> showing that because the default excerpt length is set to 55 words and manually excerpting every post would be a great time consumer. So, what are this guys putting together to get that cool effect on their sites by controlling the length of the content? Well, as a <a title="WordPress Freelancer" href="http://www.wplancer.com/wordpress-freelance-services/">WordPress freelancer</a>, I have been needing that feature myself and today I&#8217;m going to share with you how to have that feature on your site.</p>
<p>There are three different approaches to limit your excerpt or content in WordPress that you must know:</p>
<h3>1. WordPress&#8217;s Approach</h3>
<p>WordPress developers have provided us lately with a tool to limit the excerpt. I do not use it myself as I&#8217;m more conformable with another approach as I find this a little limited. To change excerpt length using the default WordPress excerpt limit approach you have to use the <a title="Plugin API/Filter Reference/excerpt length" href="http://codex.wordpress.org/Plugin_API/Filter_Reference/excerpt_length">excerpt_length</a> filter and add the following code to <em>functions.php</em> file in your theme:</p>
<pre class="php">
<span class="phpFunctionKeyword">function</span> new_excerpt_length<span class="phpOperator">(</span>$length<span class="phpOperator">)</span> <span class="phpOperator">{</span>
<span class="phpKeyword">
return </span>20;
<span class="phpOperator">}</span>
add_filter<span class="phpOperator">(</span><span class="phpString">'excerpt_length'</span>, <span class="phpString">'new_excerpt_length'</span><span class="phpOperator">)</span><span class="phpText">;</span>
</pre>
<p>Every time you will use <em>the_excerpt();</em> on your code it will output an 20-word text string for you. Right now you&#8217;ve got a question, don&#8217;t you? I know, I had it too. The question is: What if I want to use the 20-word excerpt in some places on my theme, but still be able to use the 55-word one? Or just have two or three different-length exerts to use on my theme? Well, if that is the case, the default approach is not for you, so continue reading.</p>
<h3>2. StudioPress&#8217;s Approach</h3>
<p>I don&#8217;t really know who came up with this approach originally, but I know that the guys over at <a title="StudioPress" href="http://www.studiopress.com">StudioPress</a> use it on their themes. This function is called <em>the_content_limit().</em> This is how the code that will go into the <em>functions.php</em> file looks like &#8211; lengthy huh?</p>
<pre class="php">
<span class="phpFunctionKeyword">function</span> the_content_limit<span class="phpOperator">(</span>$max_char, $more_link_text <span class="phpOperator">=</span> <span class="phpString">'<span class="phpOperator">(</span>more.<span class="phpOperator">.</span>.<span class="phpOperator">)</span>'</span>, $stripteaser <span class="phpOperator">=</span> <span class="phpNumber">0</span>, $more_file <span class="phpOperator">=</span> <span class="phpString">''</span><span class="phpOperator">)</span> <span class="phpOperator">{</span>
$content <span class="phpOperator">=</span> get_the_content<span class="phpOperator">(</span>$more_link_text, $stripteaser, $more_file<span class="phpOperator">)</span><span class="phpText">;</span>
$content <span class="phpOperator">=</span> apply_filters<span class="phpOperator">(</span><span class="phpString">'the_content'</span>, $content<span class="phpOperator">)</span><span class="phpText">;</span>
$content <span class="phpOperator">=</span> <span class="phpFunction">str_replace</span><span class="phpOperator">(</span><span class="phpString">'<span class="phpOperator">]</span><span class="phpOperator">]</span><span class="phpOperator">&gt;</span>'</span>, <span class="phpString">'<span class="phpOperator">]</span><span class="phpOperator">]</span><span class="phpOperator">&gt;</span>'</span>, $content<span class="phpOperator">)</span><span class="phpText">;</span>
$content <span class="phpOperator">=</span> <span class="phpFunction">strip_tags</span><span class="phpOperator">(</span>$content<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
if </span><span class="phpOperator">(</span><span class="phpFunction">strlen</span><span class="phpOperator">(</span><span class="phpScriptVar">$_GET</span><span class="phpOperator">[</span><span class="phpString">'p'</span><span class="phpOperator">]</span><span class="phpOperator">)</span> <span class="phpOperator">&gt;</span> <span class="phpNumber">0</span><span class="phpOperator">)</span> <span class="phpOperator">{</span>
<span class="phpFunction">echo</span> <span class="phpString">"<span class="phpOperator">&lt;</span>p<span class="phpOperator">&gt;</span>"</span><span class="phpText">;</span>
<span class="phpFunction">echo</span> $content;
<span class="phpFunction">echo</span> <span class="phpString">"&#038;nbsp<span class="phpText">;</span><span class="phpOperator">&lt;</span>a href="</span>%22<span class="phpText">;</span><span class="phpString">"<span class="phpOperator">&gt;</span><span class="phpOperator">&lt;</span>/a<span class="phpOperator">&gt;</span>
the_permalink<span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpFunction">echo</span> "</span><span class="phpString">'<span class="phpOperator">&gt;</span><span class="phpString">"<span class="phpOperator">.</span>"</span>Read More &#038;rarr<span class="phpText">;</span><span class="phpString">"<span class="phpText">;</span>
<span class="phpFunction">echo</span> "</span><span class="phpOperator">&lt;</span>/p<span class="phpOperator">&gt;</span><span class="phpString">"<span class="phpText">;</span>
<span class="phpOperator">}</span>
<span class="phpKeyword">
else </span>>if </span><span class="phpOperator">(</span><span class="phpOperator">(</span><span class="phpFunction">strlen</span><span class="phpOperator">(</span>$content<span class="phpOperator">)</span><span class="phpOperator">&gt;</span>$max_char<span class="phpOperator">)</span> &#038;amp<span class="phpText">;</span>&#038;amp<span class="phpText">;</span> <span class="phpOperator">(</span>$espacio <span class="phpOperator">=</span> <span class="phpFunction">strpos</span><span class="phpOperator">(</span>$content, "</span> <span class="phpString">", $max_char <span class="phpOperator">)</span><span class="phpOperator">)</span><span class="phpOperator">)</span> <span class="phpOperator">{</span>
$content <span class="phpOperator">=</span> <span class="phpFunction">substr</span><span class="phpOperator">(</span>$content, <span class="phpNumber">0</span>, $espacio<span class="phpOperator">)</span><span class="phpText">;</span>
$content <span class="phpOperator">=</span> $content;
<span class="phpFunction">echo</span> "</span><span class="phpOperator">&lt;</span>p<span class="phpOperator">&gt;</span><span class="phpString">"<span class="phpText">;</span>
<span class="phpFunction">echo</span> $content;
<span class="phpFunction">echo</span> "</span>.<span class="phpOperator">.</span>.<span class="phpString">"<span class="phpText">;</span>
<span class="phpFunction">echo</span> "</span>&#038;nbsp<span class="phpText">;</span><span class="phpOperator">&lt;</span>a href=<span class="phpString">"%22<span class="phpText">;</span>"</span><span class="phpOperator">&gt;</span><span class="phpOperator">&lt;</span>/a<span class="phpOperator">&gt;</span>
the_permalink<span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpFunction">echo</span> <span class="phpString">"'</span><span class="phpOperator">&gt;</span>".$more_link_text.<span class="phpString">"<span class="phpOperator">&lt;</span>/a<span class="phpOperator">&gt;</span>"</span><span class="phpText">;</span>
<span class="phpFunction">echo</span> <span class="phpString">"<span class="phpOperator">&lt;</span>/p<span class="phpOperator">&gt;</span>"</span><span class="phpText">;</span>
<span class="phpOperator">}</span>
<span class="phpKeyword">
else </span><span class="phpOperator">{</span>
<span class="phpFunction">echo</span> <span class="phpString">"<span class="phpOperator">&lt;</span>p<span class="phpOperator">&gt;</span>"</span><span class="phpText">;</span>
<span class="phpFunction">echo</span> $content;
<span class="phpFunction">echo</span> <span class="phpString">"&#038;nbsp<span class="phpText">;</span><span class="phpOperator">&lt;</span>a href="</span>%22<span class="phpText">;</span><span class="phpString">"<span class="phpOperator">&gt;</span><span class="phpOperator">&lt;</span>/a<span class="phpOperator">&gt;</span>
the_permalink<span class="phpOperator">(</span><span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpFunction">echo</span> "</span>&#039;<span class="phpOperator">&gt;</span><span class="phpString">"<span class="phpOperator">.</span>"</span>Read More &#038;rarr<span class="phpText">;</span><span class="phpString">"<span class="phpText">;</span>
<span class="phpFunction">echo</span> "</span><span class="phpOperator">&lt;</span>/p<span class="phpOperator">&gt;</span>&quot;<span class="phpText">;</span>
<span class="phpOperator">}</span>
<span class="phpOperator">}</span>
</pre>
<p>Now we have to call that function because, off course, we are not going to use the default <em>the_excerpt();</em> function. Here:</p>
<pre class="php">
<span class="phpScriptTag"><span class="phpOperator">&lt;</span><span class="phpOperator">?</span>php</span><span class="htmlText"> the_content_limit</span><span class="phpOperator">(</span>20, <span class="phpString">"<span class="phpOperator">[</span><span class="htmlText">Read more</span><span class="phpOperator">]</span>"</span><span class="phpOperator">)</span><span class="phpText">;</span> <span class="phpScriptTag"><span class="phpOperator">?</span><span class="phpOperator">&gt;</span></span>
</pre>
<p>Pretty simple to use and offers you the possibility to auto-generate a <em>Read More &#8230; </em>of you choice.</p>
<h3>C.bavota&#8217;s Apprach</h3>
<p>C.bacota &#8211; I don&#8217;t know his real name &#8211; has produced a couple of great code snippets to limit the content for both <em>the_content()</em> and <em>the_excerpt()</em>. As you may already know, <em>the_excerpt()</em> gets 55 words from <em>the_content()</em> but get rids of all the HTML tags on it, be it links, images or whatever. So, this guy produced a script that allows you to choose to use the text-only version or the html-rich version to limitedly display. I find this functions really cool and easy to use and I have been using them ever since they were produced. This is how the block of code that goes into <em>functions.php</em> looks like:</p>
<pre class="php">
<span class="phpComment">// Limit the content to certain number of words<span class="phpOperator">.</span>
</span><span class="phpFunctionKeyword">function</span> excerpt<span class="phpOperator">(</span>$num<span class="phpOperator">)</span> <span class="phpOperator">{</span>
$limit <span class="phpOperator">=</span> $num<span class="phpOperator">+</span><span class="phpNumber">1</span><span class="phpText">;</span>
$excerpt <span class="phpOperator">=</span> <span class="phpFunction">explode</span><span class="phpOperator">(</span><span class="phpString">' '</span>, get_the_excerpt<span class="phpOperator">(</span><span class="phpOperator">)</span>, $limit<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpFunction">array_pop</span><span class="phpOperator">(</span>$excerpt<span class="phpOperator">)</span><span class="phpText">;</span>
$excerpt <span class="phpOperator">=</span> <span class="phpFunction">implode</span><span class="phpOperator">(</span><span class="phpString">" "</span>,$excerpt<span class="phpOperator">)</span>.<span class="phpString">"<span class="phpOperator">.</span>.<span class="phpOperator">.</span>"</span><span class="phpText">;</span>
<span class="phpFunction">echo</span> $excerpt;
<span class="phpOperator">}</span>
<span class="phpComment">// Limit the content to certain number of words<span class="phpOperator">.</span>
</span><span class="phpFunctionKeyword">function</span> content<span class="phpOperator">(</span>$num<span class="phpOperator">)</span> <span class="phpOperator">{</span>
$limit <span class="phpOperator">=</span> $num<span class="phpOperator">+</span><span class="phpNumber">1</span><span class="phpText">;</span>
$content <span class="phpOperator">=</span> <span class="phpFunction">explode</span><span class="phpOperator">(</span><span class="phpString">' '</span>, get_the_content<span class="phpOperator">(</span><span class="phpOperator">)</span>, $limit<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpFunction">array_pop</span><span class="phpOperator">(</span>$content<span class="phpOperator">)</span><span class="phpText">;</span>
$content <span class="phpOperator">=</span> <span class="phpFunction">implode</span><span class="phpOperator">(</span><span class="phpString">" "</span>,$content<span class="phpOperator">)</span>.<span class="phpString">"<span class="phpOperator">.</span>.<span class="phpOperator">.</span>"</span><span class="phpText">;</span>
<span class="phpFunction">echo</span> $content;
<span class="phpOperator">}</span>
</pre>
<p>The above code is quite cool, but has two limitation: The first block of code, will not allow you to have a custom excerpt longer than 55 words, the same as <em>the_excerpt()</em> does, and the second one will bump image into your shorten content if you are using images in the original one. However, Mr. C.Basoda eventually thought about his and <a title="Limit Content or Excerpt" href="http://bavotasan.com/tutorials/limiting-the-number-of-words-in-your-excerpt-or-content-in-wordpress/">produced later a revised version</a> of the code that will allow you to use more than 55 words and not get images on the wrong place there. Here is the revised code:</p>
<pre class="php">
<span class="phpFunctionKeyword">function</span> excerpt<span class="phpOperator">(</span>$limit<span class="phpOperator">)</span> <span class="phpOperator">{</span>
$excerpt <span class="phpOperator">=</span> <span class="phpFunction">explode</span><span class="phpOperator">(</span><span class="phpString">' '</span>, get_the_excerpt<span class="phpOperator">(</span><span class="phpOperator">)</span>, $limit<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
if </span><span class="phpOperator">(</span><span class="phpFunction">count</span><span class="phpOperator">(</span>$excerpt<span class="phpOperator">)</span><span class="phpOperator">&gt;</span><span class="phpOperator">=</span>$limit<span class="phpOperator">)</span> <span class="phpOperator">{</span>
<span class="phpFunction">array_pop</span><span class="phpOperator">(</span>$excerpt<span class="phpOperator">)</span><span class="phpText">;</span>
$excerpt <span class="phpOperator">=</span> <span class="phpFunction">implode</span><span class="phpOperator">(</span><span class="phpString">" "</span>,$excerpt<span class="phpOperator">)</span>.<span class="phpString">'<span class="phpOperator">.</span>.<span class="phpOperator">.</span>'</span><span class="phpText">;</span>
<span class="phpOperator">}</span><span class="phpKeyword"> else </span><span class="phpOperator">{</span>
$excerpt <span class="phpOperator">=</span> <span class="phpFunction">implode</span><span class="phpOperator">(</span><span class="phpString">" "</span>,$excerpt<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpOperator">}</span>
$excerpt <span class="phpOperator">=</span> <span class="phpFunction">preg_replace</span><span class="phpOperator">(</span><span class="phpString">'`\<span class="phpOperator">[</span><span class="phpOperator">[</span>^\<span class="phpOperator">]</span><span class="phpOperator">]</span>*\<span class="phpOperator">]</span>`'</span>,<span class="phpString">''</span>,$excerpt<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
return </span>$excerpt;
<span class="phpOperator">}</span>
<span class="phpFunctionKeyword">function</span> content<span class="phpOperator">(</span>$limit<span class="phpOperator">)</span> <span class="phpOperator">{</span>
$content <span class="phpOperator">=</span> <span class="phpFunction">explode</span><span class="phpOperator">(</span><span class="phpString">' '</span>, get_the_content<span class="phpOperator">(</span><span class="phpOperator">)</span>, $limit<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
if </span><span class="phpOperator">(</span><span class="phpFunction">count</span><span class="phpOperator">(</span>$content<span class="phpOperator">)</span><span class="phpOperator">&gt;</span><span class="phpOperator">=</span>$limit<span class="phpOperator">)</span> <span class="phpOperator">{</span>
<span class="phpFunction">array_pop</span><span class="phpOperator">(</span>$content<span class="phpOperator">)</span><span class="phpText">;</span>
$content <span class="phpOperator">=</span> <span class="phpFunction">implode</span><span class="phpOperator">(</span><span class="phpString">" "</span>,$content<span class="phpOperator">)</span>.<span class="phpString">'<span class="phpOperator">.</span>.<span class="phpOperator">.</span>'</span><span class="phpText">;</span>
<span class="phpOperator">}</span><span class="phpKeyword"> else </span><span class="phpOperator">{</span>
$content <span class="phpOperator">=</span> <span class="phpFunction">implode</span><span class="phpOperator">(</span><span class="phpString">" "</span>,$content<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpOperator">}</span>
$content <span class="phpOperator">=</span> <span class="phpFunction">preg_replace</span><span class="phpOperator">(</span><span class="phpString">'/\<span class="phpOperator">[</span>.<span class="phpOperator">+</span>\<span class="phpOperator">]</span>/'</span>,<span class="phpString">''</span>, $content<span class="phpOperator">)</span><span class="phpText">;</span>
$content <span class="phpOperator">=</span> apply_filters<span class="phpOperator">(</span><span class="phpString">'the_content'</span>, $content<span class="phpOperator">)</span><span class="phpText">;</span>
$content <span class="phpOperator">=</span> <span class="phpFunction">str_replace</span><span class="phpOperator">(</span><span class="phpString">'<span class="phpOperator">]</span><span class="phpOperator">]</span><span class="phpOperator">&gt;</span>'</span>, <span class="phpString">'<span class="phpOperator">]</span><span class="phpOperator">]</span><span class="phpOperator">&gt;</span>'</span>, $content<span class="phpOperator">)</span><span class="phpText">;</span>
<span class="phpKeyword">
return </span>$content;
<span class="phpOperator">}</span>
</pre>
<p>And finally here is how you use this fantastic piece of code:</p>
<pre class="php">
<span class="phpScriptTag"><span class="phpOperator">&lt;</span><span class="phpOperator">?</span>php</span><span class="htmlText"> excerpt</span><span class="phpOperator">(</span><span class="phpString">'20'</span><span class="phpOperator">)</span><span class="phpText">;</span><span class="phpScriptTag"><span class="phpOperator">?</span><span class="phpOperator">&gt;</span></span>
// or
<span class="phpScriptTag"><span class="phpOperator">&lt;</span><span class="phpOperator">?</span>php</span><span class="htmlText"> content</span><span class="phpOperator">(</span><span class="phpString">'20'</span><span class="phpOperator">)</span><span class="phpText">;</span><span class="phpScriptTag"><span class="phpOperator">?</span><span class="phpOperator">&gt;</span></span>
</pre>
<h3>The end</h3>
<p>We are finally done.  I would also like to make clear that the approaches I presented so far are not necessary all the existing or possible ways to achieve content limitation, however this is what I know and what I thought was of value to share with you. Thanks for reading.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.wplancer.com/how-to-limit-content-in-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Easy PHP I: Introduction</title>
		<link>http://www.wplancer.com/easy-php-i-introduction/</link>
		<comments>http://www.wplancer.com/easy-php-i-introduction/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 13:36:19 +0000</pubDate>
		<dc:creator>BANAGO</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://www.wplancer.com/?p=882</guid>
		<description><![CDATA[I've been involved with PHP since I got into the web design and development world. This is because since in my beginnings I chose to use WordPress as a CMS to build websites with and since that day I have been needing PHP to build WordPress themes (and plug-ins lately). I have learned a lot of PHP tips and tricks, but I have not yet been able to study it regularly and eventually an advanced programmer as I aim.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: left; margin: 15px 10px 0 0;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.wplancer.com%2Feasy-php-i-introduction%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.wplancer.com%2Feasy-php-i-introduction%2F&amp;source=banago&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<h3>Introduction</h3>
<p><img class="size-medium wp-image-925 alignright" title="php-tux" src="http://www.wplancer.com/wp-content/php-tux-249x249.jpg" alt="php-tux" width="249" height="249" /></p>
<p>I&#8217;ve been involved with PHP since I got into the web design and development world. This is because since in my beginnings I chose to use WordPress as a CMS to build websites with and since that day I have been needing PHP to build WordPress themes (and plug-ins lately). I have learned a lot of PHP tips and tricks, but I have not yet been able to study it regularly and eventually an advanced programmer as I aim. Hence I would love to be fluent in PHP and I know that it would open a whole new business world in front of me. So, in order to push myself into the academical learning process, I will be writing down my learning experience into tutorials. In this way I hope to kill two birds with one stone: learn deeper PHP for myself and let others learn faster and hopefully better through these tutorials too. So, let&#8217;s get the hands dirty.</p>
<h3>What the Heck is PHP</h3>
<p>To get started we need to know what we are talking about. There are two different opinions as where PHP derives from. The first one tells us it stands for “Personal Home Page Tools” and the second one stands for “Hypertext Preprocessor”. No matter where it derives as a acronym, PHP is server-side programming language. It is the one responsible for taking our requests to the server and bringing to us what the server gives it. PHP can be embedded within your HTML and vice versa which is something that makes it a great language. PHP file extension end in “.php”. PHP supports a ton of databases such as: MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc, but it seems to have chosen the first one, MySQL, to marry with. The last but not the least, PHP is an open source software and is free to download and use.</p>
<h3>Why Should I Use PHP</h3>
<p>PHP is free, open source and has a great community after it. PHP is now mature and can fulfill your every wish. Furthermore, it&#8217;s aimed for the web and it gets to work done. PHP is compatible with almost all servers used today (Apache, IIS, etc.) and almost every hosting company offers PHP enabled hosting service. PHP is also easy and fun to learn as these tutorials will prove it. Moreover, PHP is so popular that if you&#8217;re looking for a career in the web design/web development industry then you just have to know it. Final word: it has proven itself over the years to be one of the best options for dynamic web applications.</p>
<h3>Am I Ready to Learn PHP</h3>
<p>Off course you are! However, you need to have a basic understanding of (X)HTML. That is all you need. However, knowing some JavaScript and CSS would make the situation a lot more fun.</p>
<h3>How to Start with PHP</h3>
<p>You need a developing environment to write and run PHP code. Basically you need to have Apache Server, MySQL and PHP installed on your computer. You can install them separately, but it is not a wise go. The best option to start with whether you are a Linux, Mac, Windows or even Solaris user is XAMPP. XAMPP is a compilation of Apache server, MySQL and PHP and a bunch of other applications like PHPMyAdmin, all-in-one. As I mentioned, it is cross-platform and really easy to use. I use it myself and I love it. You can download at <a title="Download XAMPP" href="http://www.apachefriends.org/en/xampp.html">ApacheFriends.org</a>. However, there are other options that you can consider like : WAMP specifically for Windows found at <a title="Download WAMP" href="http://www.wampserver.com">WampServer.com</a>. MAMP specifically for Mac found at <a title="Download MAMP" href="http://www.mamp.info">Mamp.info</a>. Pick and choose!</p>
<h3>Basic PHP Syntax</h3>
<p>A PHP file normally contains HTML tags, just like an HTML file, and some PHP scripting code. Below, we have an example of a simple PHP script which sends the text &#8220;PHP is cool, right?&#8221; to the browser:</p>
<pre class="php">
<span class="htmlOtherTag">&lt;html&gt;</span>
<span class="htmlOtherTag">&lt;body&gt;</span>
<span class="phpScriptTag"><span class="phpOperator">&lt;</span><span class="phpOperator">?</span>php</span> <span class="phpFunction">echo</span> <span class="phpString">"PHP is cool, right<span class="phpOperator">?</span>"</span><span class="phpText">;</span> <span class="phpScriptTag"><span class="phpOperator">?</span><span class="phpOperator">&gt;</span></span>
<span class="htmlOtherTag">&lt;/body&gt;</span>
<span class="htmlOtherTag">&lt;/html&gt;</span>
</pre>
<p>Here is the result we seen in the browser form the above PHP code.</p>
<p><img class="alignnone size-full wp-image-917" title="php-is-cool" src="http://www.wplancer.com/wp-content/php-is-cool.png" alt="" width="600" height="285" /></p>
<p>Each code line in PHP must end with a semicolon (;). The semicolon is a separator and is used to distinguish one set of instructions from another. Also, as you can see the text is wrapped with double quotes. We can use single quotes in its place too. There is a slight difference between double and single quotes that we are going to discuss in the next tutorial. Also, there are two basic statements to output text with PHP: echo and print. In the example above we have used the echo statement to output the text &#8220;My PHP Script&#8221;. Note: The file must have a .php extension. If the file has a .html extension, the PHP code will not be executed.</p>
<h3>Comments in PHP</h3>
<p>Commenting your code is a programming virtue. It is a practice of best programmers and one of principles of programming engineering. Commenting your code helps you to understand what you have been writing in the past as you might forget programming tricks and functions once in a while, also, it help others to expand and improve your code easily. So, always comment your code.</p>
<p>In PHP, we use // and # to make a single-line comment or /* and */ to make a multi-line comment block. Have a look at the example below.</p>
<pre class="php">
<span class="htmlOtherTag">&lt;html&gt;</span>
<span class="htmlOtherTag">&lt;body&gt;</span>
<span class="phpScriptTag"><span class="phpOperator">&lt;</span><span class="phpOperator">?</span>php</span>
<span class="phpComment">//This is a single line comment
</span>#This is a singe line comment too
<span class="phpComment">/*
This is a comment block<span class="phpOperator">.</span> Works the
same way<span class="phpKeyword"> as </span>commenting CSS code.
*/</span>
<span class="phpScriptTag"><span class="phpOperator">?</span><span class="phpOperator">&gt;</span></span>
<span class="htmlOtherTag">&lt;/body&gt;</span>
<span class="htmlOtherTag">&lt;/html&gt;</span>
</pre>
<p>This is how PHP looks like, but this is only the first step. To learn more fun things about PHP, read the next tutorial. <em><strong>Note</strong>: If the tutorial name does not have an active link, it means it is not posted yet, so stay tuned.</em></p>
<h3>What is next:</h3>
<ul>
<li>PHP Introduction</li>
<li><a title="PHP Variables" href="http://www.wplancer.com/easy-php-ii-variables/">PHP Variables</a></li>
<li>PHP Operators</li>
<li>PHP Arrays</li>
<li>PHP Loops
<ul>
<li>PHP If … Else</li>
<li>PHP While</li>
<li>PHP Foreach</li>
<li>PHP For</li>
<li>PHP Case</li>
<li>PHP Switch</li>
</ul>
</li>
<li>PHP Functions</li>
<li>PHP Forms
<ul>
<li>$_GET</li>
<li>$_POST</li>
<li>$_REQUEST</li>
</ul>
</li>
<li>PHP Cookies</li>
<li>PHP Sessions</li>
</ul>
<h3>Resources:</h3>
<ol>
<li>PHP Introduction: <a href="http://www.w3schools.com/PHP/php_intro.asp">http://www.w3schools.com/PHP/php_intro.asp</a></li>
<li>PHP Syntax: <a href="http://www.w3schools.com/PHP/php_syntax.asp">http://www.w3schools.com/PHP/php_syntax.asp</a></li>
<li>Learn PHP from Scratch: A Training Regimen: <a href="http://net.tutsplus.com/tutorials/php/learn-php-from-scratch-a-training-regimen/">http://net.tutsplus.com/tutorials/php/learn-php-from-scratch-a-training-regimen/</a></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.wplancer.com/easy-php-i-introduction/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
