<?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>KADIMI &#187; CMS</title>
	<atom:link href="http://www.kadimi.com/en/cms/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kadimi.com/en</link>
	<description>[Web developper, Linux addict, Technical translator...]</description>
	<lastBuildDate>Tue, 08 May 2012 17:46:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>PHP code to remove breadcrumbs in a Drupal page</title>
		<link>http://www.kadimi.com/en/drupal-disable-breadcrumbs-982</link>
		<comments>http://www.kadimi.com/en/drupal-disable-breadcrumbs-982#comments</comments>
		<pubDate>Mon, 19 Mar 2012 11:18:35 +0000</pubDate>
		<dc:creator>Nabil</dc:creator>
				<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.kadimi.com/en/?p=982</guid>
		<description><![CDATA[Sometimes you want to hide the breadcrumbs in a single page an keep it in the others, either using a module or inside a node. You can remove the breadcrumb from a Drupal page with this line of code: This how I do it: 1 drupal_set_breadcrumb&#40;array&#40;&#41;&#41;;]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want to hide the breadcrumbs in a single page an keep it in the others, either using a module or inside a node.</p>
<p>You can remove the breadcrumb from a Drupal page with this line of code:</p>
<p>This how I do it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">drupal_set_breadcrumb<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.kadimi.com/en/drupal-disable-breadcrumbs-982/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check that a user is an administrator in Drupal</title>
		<link>http://www.kadimi.com/en/drupal-check-admin-969</link>
		<comments>http://www.kadimi.com/en/drupal-check-admin-969#comments</comments>
		<pubDate>Mon, 19 Mar 2012 00:15:32 +0000</pubDate>
		<dc:creator>Nabil</dc:creator>
				<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.kadimi.com/en/?p=969</guid>
		<description><![CDATA[You can check that a user is an administrator or not like this: 1 2 3 4 5 6 if&#40;user_access&#40;'administer'&#41;&#41; &#123; print&#40;'I am an admin ))'&#41;; &#125; else &#123; print&#40;'I am not an admin (('&#41;; &#125;]]></description>
			<content:encoded><![CDATA[<p>You can check that a user is an administrator or not like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>user_access<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'administer'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'I am an admin ))'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span>  <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'I am not an admin (('</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.kadimi.com/en/drupal-check-admin-969/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drupal Views: Show count</title>
		<link>http://www.kadimi.com/en/views-count-result-964</link>
		<comments>http://www.kadimi.com/en/views-count-result-964#comments</comments>
		<pubDate>Sun, 15 Jan 2012 10:48:29 +0000</pubDate>
		<dc:creator>Nabil</dc:creator>
				<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.kadimi.com/en/?p=964</guid>
		<description><![CDATA[The view results count is stored in the view object and you can display it by adding a PHP header or footer to your view. In order to have PHP in views you need the module Views PHP, so install it first then add a header or footer with this code. 1 2 3 4 [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>view results count</strong> is stored in the view object and you can display it by adding a PHP header or footer to your view. In order to have PHP in views you need the module <a href="drupal.org/project/views_php">Views PHP</a>, so install it first then add a header or footer with this code.</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: #666666; font-style: italic;">// Dispaly count</span>
<span style="color: #000088;">$view</span> <span style="color: #339933;">=</span> views_get_current_view<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: #0000ff;">'&lt;h3&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">total_rows</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' result(s)'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/h3&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.kadimi.com/en/views-count-result-964/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drupal: Send email</title>
		<link>http://www.kadimi.com/en/drupal-send-email-935</link>
		<comments>http://www.kadimi.com/en/drupal-send-email-935#comments</comments>
		<pubDate>Mon, 09 Jan 2012 13:54:53 +0000</pubDate>
		<dc:creator>Nabil</dc:creator>
				<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.kadimi.com/en/?p=935</guid>
		<description><![CDATA[This is a quick and easy solution to send an email from Drupal using PHP, i.e a custom module. you will do it in 2 steps (I assume your module is called &#8220;mod&#8221;): Define mod_mail() (implementing hook_mail() ), this function will prepare the email Send the email using drupal_mail() Define mod_mail() 1 2 3 4 [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick and easy solution to <strong>send an email from Drupal</strong> using PHP, i.e a custom module. you will do it in 2 steps (I assume your module is called &#8220;mod&#8221;):</p>
<ul>
<li>Define mod_mail() (implementing <code>hook_mail()</code> ), this function will prepare the email</li>
<li>Send the email using drupal_mail()</li>
</ul>
<h2>Define mod_mail()</h2>

<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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Implementation of hook_mail.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> mod_mail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span><span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'basic'</span><span style="color: #339933;">:</span>
      <span style="color: #000088;">$message</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'subject'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Greetings'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$message</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'I just wanted to say hello!'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'advanced'</span><span style="color: #339933;">:</span>
      <span style="color: #000088;">$message</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'subject'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Hello @username'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'username'</span><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: #000088;">$message</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Thank you for joining @site_name!'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'@site_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'site_name'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
      <span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">/* Do nothing */</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Sending the email</h2>
<p>In order to send the email you need to decide on 2 parameters (optionally, a 3rd):</p>
<ol>
<li>The recipent (email address)</li>
<li>The key, in this example this would be &#8216;basic&#8217; or &#8216;advanced&#8217;</li>
<li> The $params to pass to <code>mod_mail()</code>, in our example it&#8217;s only needed if we are using the key &#8216;advanced&#8217;</li>
</ol>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Basic example ($key = 'basic')</span>
<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;someone@example.com&quot;</span><span style="color: #339933;">;</span>
drupal_mail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mod'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'basic'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #339933;">,</span> language_default<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// Advanced example ($key = 'advanced')</span>
<span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;someone@example.com&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Someone'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'site_name'</span> <span style="color: #339933;">=</span> variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'site_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
drupal_mail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mod'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'advanced'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$email</span><span style="color: #339933;">,</span> language_default<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.kadimi.com/en/drupal-send-email-935/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drupal 7: Get files public directory path</title>
		<link>http://www.kadimi.com/en/drupal-files-directory-923</link>
		<comments>http://www.kadimi.com/en/drupal-files-directory-923#comments</comments>
		<pubDate>Sat, 24 Dec 2011 11:30:12 +0000</pubDate>
		<dc:creator>Nabil</dc:creator>
				<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.kadimi.com/en/?p=923</guid>
		<description><![CDATA[We used to get the files directory using file_directory_path() in Drupal 5 and 6, the function was removed with Drupal 7 but you can still get the files public directory like this: 1 2 echo variable_get&#40;'file_public_path', conf_path&#40;&#41; . '/files'&#41;; // Output: sites/default/files]]></description>
			<content:encoded><![CDATA[<p>We used to get the files directory using <code>file_directory_path()</code> in Drupal 5 and 6, the function was removed with Drupal 7 but you can still get the files public directory like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> variable_get<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'file_public_path'</span><span style="color: #339933;">,</span> conf_path<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/files'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">// Output: sites/default/files</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.kadimi.com/en/drupal-files-directory-923/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Drupal : Get path and verify if it&#8217;s an alias</title>
		<link>http://www.kadimi.com/en/drupal-get-path-and-verify-if-its-an-alias-919</link>
		<comments>http://www.kadimi.com/en/drupal-get-path-and-verify-if-its-an-alias-919#comments</comments>
		<pubDate>Fri, 23 Dec 2011 20:48:21 +0000</pubDate>
		<dc:creator>Nabil</dc:creator>
				<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.kadimi.com/en/?p=919</guid>
		<description><![CDATA[This is how I get the current path and/or alias in Drupal: After this code has been executed: $path will hold the internal drupal path $alias will hold that path alias if the path in the url is actually an alias, otherwise FALSE; 1 2 3 4 5 6 $path_from_url = isset&#40;$_GET&#91;'q'&#93;&#41; ? $_GET&#91;'q'&#93; : [...]]]></description>
			<content:encoded><![CDATA[<p>This is how I get the current path and/or alias in Drupal:<br />
After this code has been executed:<br />
<code>$path</code> will hold <strong>the internal drupal path</strong><br />
<code>$alias</code> will hold <strong>that path alias</strong> if the path in the url is actually an alias, otherwise FALSE;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$path_from_url</span> <span style="color: #339933;">=</span> <span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'q'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'&lt;front&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$path</span> <span style="color: #339933;">=</span> drupal_get_normal_path<span style="color: #009900;">&#40;</span><span style="color: #000088;">$path_from_url</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;">$path</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$path_from_url</span><span style="color: #009900;">&#41;</span> 
  <span style="color: #000088;">$alias</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">else</span> 
  <span style="color: #000088;">$alias</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$path_from_url</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.kadimi.com/en/drupal-get-path-and-verify-if-its-an-alias-919/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix &#8220;xyz.widget is not a function&#8221; when jQuerying in Drupal</title>
		<link>http://www.kadimi.com/en/widget-is-not-a-function-897</link>
		<comments>http://www.kadimi.com/en/widget-is-not-a-function-897#comments</comments>
		<pubDate>Mon, 31 Oct 2011 18:13:50 +0000</pubDate>
		<dc:creator>Nabil</dc:creator>
				<category><![CDATA[Drupal]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.kadimi.com/en/?p=897</guid>
		<description><![CDATA[The error looks like: c.widget is not a function Or: d.widget is not a function I get this error when I do theming or module development for Drupal. Basically this tells you that the file jquery.ui.widget.js is missing. check the code you were writting and add that file to Drupal like this: 1 drupal_add_js&#40;'misc/ui/jquery.ui.widget.min.js'&#41;;]]></description>
			<content:encoded><![CDATA[<p>The error looks like:</p>
<blockquote><p>c.widget is not a function</p></blockquote>
<p>Or:</p>
<blockquote><p>d.widget is not a function</p></blockquote>
<p>I get this error when I do theming or module development for Drupal. Basically this tells you that the file jquery.ui.widget.js is missing. check the code you were writting and add that file to Drupal like this:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">drupal_add_js<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'misc/ui/jquery.ui.widget.min.js'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.kadimi.com/en/widget-is-not-a-function-897/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Age from date of birth in Drupal 7</title>
		<link>http://www.kadimi.com/en/age-from-date-of-birth-in-drupal-7-777</link>
		<comments>http://www.kadimi.com/en/age-from-date-of-birth-in-drupal-7-777#comments</comments>
		<pubDate>Mon, 19 Sep 2011 22:46:38 +0000</pubDate>
		<dc:creator>Nabil</dc:creator>
				<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.kadimi.com/en/?p=777</guid>
		<description><![CDATA[<a href="http://www.kadimi.com/en/age-from-date-of-birth-in-drupal-7-777"><img align="left" hspace="5" width="150" height="150" src="http://www.kadimi.com/en/wp-content/uploads/date_of_birth_field-150x150.png" class="alignleft wp-post-image tfe" alt="Date of birth field" title="Date of birth field" /></a>In this tutorial I&#8217;m gonna show you how to calculate and display properly the age from a date CCK field the simplest way. The method I&#8217;m about to show you doesn&#8217;t need the Views module and if you use Views you&#8217;ll find that it&#8217;s totally compatible without adding any PHP code. Requirements Before starting I [...]]]></description>
			<content:encoded><![CDATA[<p>In this tutorial I&#8217;m gonna show you how to calculate and display properly the age from a date CCK field the simplest way. The method I&#8217;m about to show you doesn&#8217;t need the Views module and if you use Views you&#8217;ll find that it&#8217;s totally compatible without adding any PHP code.</p>
<h2>Requirements</h2>
<p>Before starting I want you to meet the following requirements in order to follow this tutorial:</p>
<ul>
<li>Install and enable the <a title="Drupal Computed Field Module" href="http://drupal.org/project/computed_field">Computed_field</a> module</li>
<li>Install and enable the <a title="Drupal Date Module" href="http://drupal.org/project/date">Date</a> module (Date API, Date &amp; Date popup)</li>
<li>Install and enable the <a title="Drupal Rules Module" href="http://www.kadimi.com/en/resume">Rules</a> module</li>
<li>Enable the core PHP filter module</li>
<li>Add a date field to an existing content type (let&#8217;s call it <strong>field_dob</strong>)<code></code></li>
</ul>
<p>For the purpose of this tutorial I created a very simple content type named <strong>Candidate</strong> with only 2 fields:</p>
<ul>
<li>I changed the title from <strong>Title</strong> to <strong>Full name</strong> and removed the <strong>Body</strong> field</li>
<li>I added a Date field and named it <strong>field_dob</strong>
<p><div id="attachment_795" class="wp-caption alignnone" style="width: 310px"><a href="http://www.kadimi.com/en/wp-content/uploads/date_of_birth_field.png"><img class="size-medium wp-image-795" title="Date of birth field" src="http://www.kadimi.com/en/wp-content/uploads/date_of_birth_field-300x69.png" alt="Date of birth field" width="300" height="69" /></a><p class="wp-caption-text">Date of birth field - Click to enlarge</p></div></li>
</ul>
<h2>Add a computed field</h2>
<p>Now let&#8217;s add a new field with <strong>Age</strong> as a label and <strong>field_age</strong> as a name and <strong>Computed</strong> as a field type.<br />
In the next screen we will set the field settings:</p>
<ul>
<li>Computed Code (PHP):

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$entity_field</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">-</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entity</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">field_dob</span><span style="color: #009900;">&#91;</span>LANGUAGE_NONE<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><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: #cc66cc;">86400</span> <span style="color: #339933;">/</span> <span style="color:#800080;">365.25</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>Display Code (PHP):

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$display_output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$entity_field_item</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</li>
<li>Data type:<strong> Decimal</strong></li>
<li>Decimal Scale (decimal): <strong>3</strong></li>
</ul>
<h2>Add content and test</h2>
<p>Now let&#8217;s add a few items and see if it works as we expected, I added a couple of entries and tested:</p>
<ul>
<li>Old KADIMI (born on 1 Jan 1990) =&gt; Age computed 21</li>
<li>Young KADIMI (born on 2 Jan 1990) =&gt; Age computed 21</li>
</ul>
<h2>Sorting with Views</h2>
<p>You may want to use the Views module to accommodate the output to your needs, one of the features of the Views module is that it enable you to sort results.</p>
<p>So what if we wanted to sort our candidates by age, Both KADIMI brothers (Old and Young) are 21 years old but Old is 1 day older that Young, for Drupal they have the same age and the result of the sorting may be inaccurate, actually we already fixed this issue by storing the age as a decimal number with 3 decimal points and displaying it as an integer (by using floor), by looking into the database table <strong>field_data_field_age</strong> with phpMyAdmin:</p>
<ul>
<li>Young KADIMI is 21.570 years old</li>
<li>Old KADIMI is 21.573 yeas old</li>
</ul>
<h2>Update age</h2>
<p>In order to recompute a candidate age we must re-save that candidate node, one way to do this is using Rules and Drupal cron</p>
<ul>
<li>Visit /admin/config/workflow/rules/reaction/add to add a rule, give it a descriptive name like &#8220;Re-save candidates nodes&#8221;<br />
Set React on event to: <strong>Cron maintenance tasks are performed</strong></li>
<li>Add a new action<br />
Set Select the action to add to: <strong>Execute custom PHP code</strong><br />
Set the PHP code to:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$old</span>   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1 day'</span><span style="color: #339933;">;</span>      <span style="color: #666666; font-style: italic;"># Content is considered outdated if older than {$old}
</span><span style="color: #000088;">$type</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'candidate'</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;"># Apply to nodes of type {$type}
</span><span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">20</span><span style="color: #339933;">;</span>           <span style="color: #666666; font-style: italic;"># Update {$count} nodes per cron
</span> 
<span style="color: #000088;">$old</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;now - <span style="color: #006699; font-weight: bold;">$old</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$nids</span> <span style="color: #339933;">=</span> db_query_range<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'
  SELECT n.nid
  FROM {node} n 
  WHERE n.type = :type AND n.created &lt; :old 
  ORDER BY n.created ASC'</span><span style="color: #339933;">,</span>
  <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$count</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">':old'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$old</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;:type&quot;</span><span style="color: #339933;">=&gt;</span><span style="color: #000088;">$type</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$nids</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$nid</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$node</span> <span style="color: #339933;">=</span> node_load<span style="color: #009900;">&#40;</span><span style="color: #000088;">$nid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   node_save<span style="color: #009900;">&#40;</span><span style="color: #000088;">$node</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Tweak the 3 parameters in a way that suits your needs and that&#8217;s it!</li>
</ul>
<h2>Need help?</h2>
<p>If  you found this tutorial difficult and couldn&#8217;t follow the instructions you can ask for help on the comments section or you can <a title="Hire Me" href="http://www.kadimi.com/en/hire-me">hire me and I will take care of this for you</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kadimi.com/en/age-from-date-of-birth-in-drupal-7-777/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Drupal : Add classes to $body_class</title>
		<link>http://www.kadimi.com/en/drupal-add-classes-704</link>
		<comments>http://www.kadimi.com/en/drupal-add-classes-704#comments</comments>
		<pubDate>Tue, 28 Sep 2010 03:04:59 +0000</pubDate>
		<dc:creator>Nabil</dc:creator>
				<category><![CDATA[Drupal]]></category>

		<guid isPermaLink="false">http://www.kadimi.com/en/?p=704</guid>
		<description><![CDATA[$body_classes variable and how it&#8217;s used By default, Drupal provides Drupal themes coders with a variable $body_classes which contains a list of space separated keywords that you can use to style your page depending on different factors including the user status (logged in or not), the page he is viewing (frontpage, node, page, story&#8230;). Make [...]]]></description>
			<content:encoded><![CDATA[<h2>$body_classes variable and how it&#8217;s used</h2>
<p>By default, Drupal provides Drupal themes coders with a variable <strong>$body_classes</strong> which contains a list of space separated keywords that you can use to style your page depending on different factors including the user status (logged in or not), the page he is viewing (frontpage, node, page, story&#8230;).</p>
<p>Make use of <strong>$body_classes</strong> on your theme like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;body class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">print</span> <span style="color: #000088;">$body_classes</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;</pre></td></tr></table></div>

<p>Here are a few exmaples of $body_classes for different visitors:</p>
<ul>
<li><strong>$body_styles</strong>: front not-logged-in page-node no-sidebars<strong> </strong></li>
<li><strong>$body_styles</strong>: not-front logged-in page-node node-type-blog no-sidebars</li>
</ul>
<p>You can easily tell that the first line corresponds to a user not logged in, he is viewing the frontpage, the 2nd line is from a user who is logged in and is probably reading a blog post. Both visitors are viewing a page with no sidebars (the admin of the site decided so)</p>
<p>It&#8217;s very easy, using these classes to present things differently depending on what suits your needs (user status, current node type, sidebars)</p>
<p>You can find more about the logic behind this variable one the <a href="http://api.drupal.org/api/function/template_preprocess_page/6">Drupal API Reference</a></p>
<h2>Add more classes to $body_classes</h2>
<p>Now what if you need more than those default classes, you can think of many examples; I &#8211; as the administrator of a Drupal site &#8211; want a big red banner to remind me to logout if I&#8217;m using my administrator account instead of my normal account.</p>
<p>The proper way to this is by using the theme hook <a href="http://api.drupal.org/api/function/template_preprocess_page/6">template_preprocess_page</a> like this (replace theme_name), we add the function theme_name_preprocess_page to our template.php file, Drupal will automatically run that code and add the new classes that we want:</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;">&lt;body class=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> theme_name_preprocess_page<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$variables</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$body_classes</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body_classes'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// if the user is the admin add the class is_admin</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'is_admin'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$body_classes</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'is_admin'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">// ... more magic here if you want to add  more classes ...</span>
  <span style="color: #000088;">$variables</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'body_classes'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body_classes</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>&quot;&gt;</pre></td></tr></table></div>

<p>Now you can add more if clauses to the function to have the classes you need.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kadimi.com/en/drupal-add-classes-704/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress page navigation without using a plugin</title>
		<link>http://www.kadimi.com/en/wp-paged-navigation-without-plugin-655</link>
		<comments>http://www.kadimi.com/en/wp-paged-navigation-without-plugin-655#comments</comments>
		<pubDate>Thu, 19 Aug 2010 03:45:04 +0000</pubDate>
		<dc:creator>Nabil</dc:creator>
				<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://www.kadimi.com/en/?p=655</guid>
		<description><![CDATA[<a href="http://www.kadimi.com/en/wp-paged-navigation-without-plugin-655"><img align="left" hspace="5" width="150" src="http://www.kadimi.com/en/wp-content/uploads/navigation.png" class="alignleft wp-post-image tfe" alt="wp page navigation" title="" /></a>Here is a small&#8230; yes, a small function for displaying a paged navigation in your WordPress powered blog without using any plugin. The function is self-explaining, it accepts one optional parameter, the number of links to show without counting the previous and next buttons. It accepts your language The first, previous, next and last buttons [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.kadimi.com/en/wp-content/uploads/navigation.png" alt="wp page navigation" /><br />
Here is a small&#8230; yes, a small function for displaying a paged navigation in your WordPress powered blog without using any plugin.</p>
<p>The function is self-explaining, it accepts one optional parameter, the number of links to show without counting the previous and next buttons.</p>
<h2>It accepts your language</h2>
<p>The first, previous, next and last buttons text can be set to anything you want from within the function, you probably don&#8217;t want to change the presets, the arrows work just fine and don&#8217;t need any translation, but it you want to put something else and if you are making a template that is meant for distribution, I advise that you use the __() function, example:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$first_txt</span> <span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'First'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'theme_textdomain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$previous_txt</span> <span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Previous'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'theme_textdomain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$last_txt</span> <span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Last'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'theme_textdomain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$next_txt</span> <span style="color: #339933;">=</span> __<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Next'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'theme_textdomain'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h2>The function</h2>
<p>This is the function:</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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * get_paged_navigation displays a paged navigation
 * @param int $number_of_pages_to_show
 * @author Nabil Kadimi
 * @link http://www.kadimi.com/
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> get_paged_navigation<span style="color: #009900;">&#40;</span><span style="color: #000088;">$number_of_pages_to_show</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$current_page_number</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'paged'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$number_of_pages</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>int<span style="color: #009900;">&#41;</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wp_query'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">max_num_pages</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$first_txt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'«'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$previous_txt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'‹'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$next_txt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'›'</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$last_txt</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'»'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$number_of_pages</span> <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</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: #000088;">$current_page_number</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$current_page_number</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$last_head_page_number</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$number_of_pages_to_show</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$firt_tail_page_number</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$number_of_pages</span> <span style="color: #339933;">-</span> <span style="color: #990000;">floor</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$number_of_pages_to_show</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$current_page_number</span> <span style="color: #339933;">&lt;=</span> <span style="color: #000088;">$last_head_page_number</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$page_first_shown</span> <span style="color: #339933;">=</span>  <span style="color: #cc66cc;">1</span> <span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$current_page_number</span> <span style="color: #339933;">&gt;=</span> <span style="color: #000088;">$firt_tail_page_number</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$page_first_shown</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$number_of_pages</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$number_of_pages_to_show</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">else</span>
		<span style="color: #000088;">$page_first_shown</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$current_page_number</span> <span style="color: #339933;">-</span> <span style="color: #990000;">ceil</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$number_of_pages_to_show</span><span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// First arrows</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page_first_shown</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">,</span>get_pagenum_link<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$first_txt</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> get_previous_posts_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$previous_txt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">// Linked page numbers</span>
	<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$number_of_pages_to_show</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">&lt;</span><span style="color: #000088;">$number_of_pages</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a class=&quot;current&quot; href=&quot;'</span><span style="color: #339933;">,</span> get_pagenum_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$page_first_shown</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$i</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$page_first_shown</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$i</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Last arrows</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$page_first_shown</span> <span style="color: #339933;">+</span> <span style="color: #000088;">$number_of_pages_to_show</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$number_of_pages</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> get_next_posts_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$next_txt</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;a href=&quot;'</span><span style="color: #339933;">,</span> get_pagenum_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$number_of_pages</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&quot;&gt;'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$last_txt</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;/a&gt; '</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h2>Usage</h2>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">get_paged_navigation<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h2>With formatting</h2>
<p>One more thing, if the pagination will have any formatting surrounding it, you can have a conditional statement so that the formatting doesn&#8217;t appear if the pagination is not needed (there is only 1 page), here is an example:</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: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'wp_query'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">max_num_pages</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;div class=&quot;navigation&quot;&gt;'</span><span style="color: #339933;">;</span>
	get_paged_navigation<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: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.kadimi.com/en/wp-paged-navigation-without-plugin-655/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

