<?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>L&#039;Arbre à Hélices</title>
	<atom:link href="http://www.arbre-helices.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.arbre-helices.com</link>
	<description>Un site utilisant WordPress</description>
	<lastBuildDate>Fri, 11 May 2012 15:05:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Page contact pour WordPress</title>
		<link>http://www.arbre-helices.com/2012/03/23/page-contact-pour-wordpress/</link>
		<comments>http://www.arbre-helices.com/2012/03/23/page-contact-pour-wordpress/#comments</comments>
		<pubDate>Fri, 23 Mar 2012 11:15:11 +0000</pubDate>
		<dc:creator>Antoine</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[contact]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.arbre-helices.com/?p=467</guid>
		<description><![CDATA[<p>WordPress ne dispose pas de page de contact par défaut. Il faut, donc, si on en a besoin, développer cette page. Ci-dessous une page contact, qu'il faudra assigner dans la partie administration de WordPress à une page contact que l'on devra créer.</p>]]></description>
			<content:encoded><![CDATA[<p>WordPress ne dispose pas de page de contact par défaut. Il faut, donc, si on en a besoin, développer cette page. Ci-dessous une page contact, qu&#8217;il faudra assigner dans la partie administration de WordPress à une page contact que l&#8217;on devra créer.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
 * Template Name: contact
 */</span>
&nbsp;
<span style="color: #000088;">$hasError</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nb1</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$nb2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'EMAIL_TECHNIQUE'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'toto@ww.com'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'NAME_SITE'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'Nom site'</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: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>wp_verify_nonce<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name_contact'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'action_contact'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$hasError</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</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: #000088;">$nom</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nom'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$commentaire</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'commentaire'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">;</span> 
&nbsp;
    <span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'From: Site &lt;'</span><span style="color: #339933;">.</span>EMAIL_TECHNIQUE<span style="color: #339933;">.</span><span style="color: #0000ff;">'&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span><span style="color: #0000ff;">'From: &quot;nom&quot;'</span><span style="color: #339933;">.</span>EMAIL_TECHNIQUE<span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span><span style="color: #0000ff;">'Reply-To: '</span><span style="color: #339933;">.</span>EMAIL_TECHNIQUE<span style="color: #339933;">.</span><span style="color: #0000ff;">''</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span><span style="color: #0000ff;">'Content-Type: text/html; charset=&quot;iso-8859-1&quot;'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span><span style="color: #0000ff;">'Content-Transfer-Encoding: 8bit'</span><span style="color: #339933;">;</span> 
&nbsp;
    <span style="color: #666666; font-style: italic;">//test numérique pour éviter envoi de mail bizard</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'calcul'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nb1'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nb2'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$hasError</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#^[\w.-]+@[\w.-]+\.[a-zA-Z]{2,5}$#'</span><span style="color: #339933;">,</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</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: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span><span style="color: #0000ff;">''</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$hasError</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #000088;">$hasError</span>   <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$nom</span> <span style="color: #339933;">=</span> <span style="color: #990000;">utf8_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nom'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$commentaire</span> <span style="color: #339933;">=</span> <span style="color: #990000;">utf8_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'commentaire'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
       <span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;h1&gt;&quot;</span><span style="color: #339933;">.</span>NAME_SITE<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/h1&gt;&quot;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;p&gt;email: <span style="color: #006699; font-weight: bold;">{$_POST['email']}</span>, nom: <span style="color: #006699; font-weight: bold;">$nom</span>&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;p&gt;<span style="color: #006699; font-weight: bold;">$commentaire</span>&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;&lt;p&gt;------------------------------------&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$message</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'&lt;p style=&quot;color:#CCC; font-size:9px; &quot;&gt;L\'Arbre &amp;agrave; H&amp;eacute;lices site r&amp;eacute;alis&amp;eacute; par Antoine&lt;/p&gt;'</span><span style="color: #339933;">;</span>
       <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span> EMAIL_TECHNIQUE<span style="color: #339933;">,</span> <span style="color: #0000ff;">'Contact Site'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #000088;">$hasSent</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</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: #000088;">$hasSent</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>    
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=&quot;content&quot;&gt;
     &lt;h2 class=&quot;title-contact&quot;&gt;Contact&lt;/h2&gt;
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$hasSent</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
     &lt;form id=&quot;contact-page&quot; method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; &gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_nonce_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action_contact'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'name_contact'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
         &lt;p&gt;Nom : &lt;input type=&quot;text&quot; name=&quot;nom&quot; value=&quot;&quot; /&gt;&lt;/p&gt;
         &lt;p&gt;Email : &lt;input type=&quot;text&quot; name=&quot;email&quot; value=&quot;&quot; /&gt;&lt;/p&gt;
         &lt;p&gt; Calculer : <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nb1</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;+&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$nb2</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;input type=&quot;text&quot; name=&quot;calcul&quot; value=&quot;&quot; /&gt; 
          &lt;input type=&quot;hidden&quot; name=&quot;nb1&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nb1</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;nb2&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nb2</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
          &lt;/p&gt;
         &lt;h3&gt;Commentaires&lt;/h3&gt;
         &lt;span id=&quot;msg-commentaire&quot;&gt;&lt;/span&gt;
         &lt;textarea name=&quot;commentaire&quot;  rows=&quot;5&quot; cols=&quot;50&quot; &gt;&lt;/textarea&gt;
         &lt;p&gt;&lt;input  type=&quot;submit&quot; name=&quot;envoyer_contact&quot; /&gt;&lt;/p&gt;
    &lt;/form&gt;
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$hasSent</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
        &lt;p&gt;Merci, pour votre message on vous contactera bientôt&lt;/p&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
        &lt;p&gt;Votre mail n'a pas été envoyé .&lt;/p&gt;
        &lt;form id=&quot;contact-page&quot; method=&quot;post&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; &gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_nonce_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'action_contact'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'name_contact'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
            &lt;p&gt;Nom : &lt;input type=&quot;text&quot; name=&quot;nom&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span>  <span style="color: #000088;">$nom</span>   <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;&lt;/p&gt;
         &lt;p&gt;Email : &lt;input type=&quot;text&quot; name=&quot;email&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span>  esc_attr<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$email</span> <span style="color: #009900;">&#41;</span>  <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;&lt;/p&gt;
          &lt;p&gt; Calculer : <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nb1</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;+&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$nb2</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;input type=&quot;text&quot; name=&quot;calcul&quot; value=&quot;&quot; /&gt; 
          &lt;input type=&quot;hidden&quot; name=&quot;nb1&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nb1</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
          &lt;input type=&quot;hidden&quot; name=&quot;nb2&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$nb2</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
          &lt;/p&gt;
         &lt;h3&gt;Commentaires&lt;/h3&gt;
          &lt;div id=&quot;msg-commentaire&quot;&gt;&lt;/div&gt;
         &lt;textarea name=&quot;commentaire&quot; &gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span>  <span style="color: #000088;">$commentaire</span> <span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;/textarea&gt;
         &lt;p&gt;&lt;input  type=&quot;submit&quot; name=&quot;envoyer_contact&quot; /&gt;&lt;/p&gt;
        &lt;/form&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;&lt;!-- content --&gt;
&lt;div id=&quot;sidebar&quot;&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Pour réaliser une page contact, il faut vérifier côté client (navigateur) les différents champs du formulaire, avant d&#8217;envoyer les données au serveur; et également vérifier les données côté serveur. On placera le code suivant dans le fichier functions.php pour relier les scripts aux templates de WordPress </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_enqueue_scripts'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'verification_contact'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> verification_contact<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">//L'ajout du script dépend de la page Contact</span>
   <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Contact'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        wp_register_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'general_script'</span><span style="color: #339933;">,</span>
        get_template_directory_uri<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/js/general_script.js'</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// enqueue the script</span>
        wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'general_script'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span> 
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Exemple de code que l&#8217;on utilisé pour vérifier en JQuery les champs du formulaire. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/* 
 * JS vérification 
 * auteur : Antoine
 * JQuery est utilisé à la place de $ pour éviter les conflits
 * entre les différents framework javascript dans WordPress
 */</span>
jQuery<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ready<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#contact-page'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>submit<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">var</span> valid <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">var</span> commentaire <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;textarea[name=commentaire]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> jQuery<span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span>commentaire<span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                commentaire<span style="color: #339933;">.</span>css<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'background-color'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'red'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                valid <span style="color: #339933;">=</span>  <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
                jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#msg-commentaire&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #666666; font-style: italic;">//un minum de caractère et pas plus de deux liens dans le champ texte</span>
                <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> commentaire<span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>length <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">10</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                    jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#msg-commentaire&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>append<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;Attention le message doit faire plus de 10 caractères&lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    commentaire<span style="color: #339933;">.</span>css<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'background-color'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'red'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                    valid <span style="color: #339933;">=</span>  <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
                    commentaire<span style="color: #339933;">.</span>css<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'background-color'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'white'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #009900;">&#125;</span>
         <span style="color: #666666; font-style: italic;">//email</span>
        <span style="color: #000000; font-weight: bold;">var</span> email <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;input[name=email]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> jQuery<span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span>email<span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</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: #339933;">!</span>jQuery<span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span>email<span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>match<span style="color: #009900;">&#40;</span><span style="color: #339933;">/</span>^<span style="color: #009900;">&#91;</span>a<span style="color: #339933;">-</span>zA<span style="color: #339933;">-</span>Z0<span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">.</span>_<span style="color: #339933;">-</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">+@</span><span style="color: #009900;">&#91;</span>a<span style="color: #339933;">-</span>zA<span style="color: #339933;">-</span>Z0<span style="color: #339933;">-</span><span style="color: #cc66cc;">9</span><span style="color: #339933;">.-</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#91;</span><span style="color: #339933;">.</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>a<span style="color: #339933;">-</span>zA<span style="color: #339933;">-</span>Z<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#125;</span>$<span style="color: #339933;">/</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
                email<span style="color: #339933;">.</span>css<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'background-color'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'red'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                valid <span style="color: #339933;">=</span>  <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
               email<span style="color: #339933;">.</span>css<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'background-color'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'white'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #666666; font-style: italic;">//nom</span>
        <span style="color: #000000; font-weight: bold;">var</span> nom <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;input[name=nom]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> jQuery<span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span>nom<span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                nom<span style="color: #339933;">.</span>css<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'background-color'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'red'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                valid <span style="color: #339933;">=</span>  <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
                nom<span style="color: #339933;">.</span>css<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'background-color'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'white'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//numerique calcul</span>
        jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#msg-calcul&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">var</span> calcul <span style="color: #339933;">=</span> jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;input[name=calcul]&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> jQuery<span style="color: #339933;">.</span><span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span>calcul<span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
                calcul<span style="color: #339933;">.</span>css<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'background-color'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'red'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                jQuery<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#msg-calcul&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>append<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;p&gt;Attention, il faut faire l'opération numérique&lt;/p&gt;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                valid <span style="color: #339933;">=</span>  <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
                calcul<span style="color: #339933;">.</span>css<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">'background-color'</span><span style="color: #339933;">:</span><span style="color: #0000ff;">'white'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> valid<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.arbre-helices.com/2012/03/23/page-contact-pour-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Développez un thème WordPress</title>
		<link>http://www.arbre-helices.com/2012/03/22/developpez-un-theme-wordpress/</link>
		<comments>http://www.arbre-helices.com/2012/03/22/developpez-un-theme-wordpress/#comments</comments>
		<pubDate>Thu, 22 Mar 2012 15:10:34 +0000</pubDate>
		<dc:creator>Antoine</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.arbre-helices.com/?p=457</guid>
		<description><![CDATA[Installation d&#8217;un nouveau thème dans WordPress Dans le dossier wp-content de WordPress se trouve le dossier themes, c&#8217;est dans ce dossier qu&#8217;il faut créer un dossier portant le nom du thème que l&#8217;on veut développer, par exemple arbre-helices; pour commencer on doit avoir au minimum les fichiers suivants : style.css, installe et paramètre le template [...]]]></description>
			<content:encoded><![CDATA[<h3>Installation d&#8217;un nouveau thème dans WordPress</h3>
<p>Dans le dossier wp-content de WordPress se trouve le dossier themes, c&#8217;est dans ce dossier qu&#8217;il faut créer un dossier portant le nom du thème que l&#8217;on veut développer, par exemple arbre-helices; pour commencer on doit avoir au minimum les fichiers suivants : </p>
<ul class="menu-g square-1">
<li>style.css, installe et paramètre le template dans WordPress</li>
<li>index.php, temlpate de base </li>
<li>screenshot.png, miniature apparait dans l&#8217;admin de WordPress</li>
</ul>
<h3>Le fichier style.css</h3>
<p>Ce fichier détermine les styles CSS du site, il paramètre et installe également le thème dans WordPress. Il doit commencer par des commentaires spécifiques, Theme Name correspond au nom du thème, etc : </p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
Theme Name: Arbre à Hélices
Theme URI: http://www.arbre-helices.com
Description: thème du site Arbre à Hélices
Version: 1.0
Author: Antoine 
Author URI: http://www.arbre-helices.com/contact
Tags: two-columns, post-formats
Thème de l'Arbre à Hélices
*/</span>
<span style="color: #808080; font-style: italic;">/*--------- reset -----------*/</span>
a img<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #993333;">none</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
html<span style="color: #00AA00;">,</span> body<span style="color: #00AA00;">,</span>fieldset<span style="color: #00AA00;">,</span> form<span style="color: #00AA00;">,</span>legend<span style="color: #00AA00;">,</span> h1<span style="color: #00AA00;">,</span> h2<span style="color: #00AA00;">,</span> h3<span style="color: #00AA00;">,</span> h4<span style="color: #00AA00;">,</span> h5<span style="color: #00AA00;">,</span> h6<span style="color: #00AA00;">,</span> p<span style="color: #00AA00;">,</span> blockquote<span style="color: #00AA00;">,</span> pre<span style="color: #00AA00;">,</span> code<span style="color: #00AA00;">,</span>q<span style="color: #00AA00;">,</span>
dl<span style="color: #00AA00;">,</span>ol<span style="color: #00AA00;">,</span> ul<span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>padding<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
html<span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">100%</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
img <span style="color: #00AA00;">&#123;</span><span style="color: #000000; font-weight: bold;">vertical-align</span><span style="color: #00AA00;">:</span><span style="color: #993333;">baseline</span><span style="color: #00AA00;">;</span><span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
<span style="color: #808080; font-style: italic;">/*         =style de base    */</span>
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
body<span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">font-size</span><span style="color: #00AA00;">:</span><span style="color: #933;">12px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #808080; font-style: italic;">/*harmoniser les espaces, fusion des marges des éléments frères*/</span>
h1<span style="color: #00AA00;">,</span> h2<span style="color: #00AA00;">,</span> h3<span style="color: #00AA00;">,</span> h4<span style="color: #00AA00;">,</span> h5<span style="color: #00AA00;">,</span> h6 <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">15px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">10px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>  <span style="color: #808080; font-style: italic;">/* sup entre les éléments */</span>
<span style="color: #00AA00;">&#125;</span>
ul<span style="color: #00AA00;">,</span> ol<span style="color: #00AA00;">,</span> p <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #933;">7px</span> <span style="color: #cc66cc;">0</span> <span style="color: #933;">5px</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>  <span style="color: #808080; font-style: italic;">/* sup entre les éléments */</span>
<span style="color: #00AA00;">&#125;</span>
hr.<span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">clear</span><span style="color: #00AA00;">:</span><span style="color: #993333;">both</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">visibility</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
<span style="color: #808080; font-style: italic;">/*         =structure        */</span>
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
<span style="color: #cc00cc;">#main</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#header</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#content</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#sidebar</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#footer</span><span style="color: #00AA00;">&#123;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
<span style="color: #808080; font-style: italic;">/*           =header         */</span>
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
<span style="color: #808080; font-style: italic;">/*           =content        */</span>
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
<span style="color: #808080; font-style: italic;">/*           =sidebar        */</span>
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
<span style="color: #808080; font-style: italic;">/*           =footer         */</span>
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span>
<span style="color: #808080; font-style: italic;">/*           =autres         */</span>
<span style="color: #808080; font-style: italic;">/*---------------------------*/</span></pre></div></div>

<h3>Les templates</h3>
<p class="comment" >Un modèle de page ou template est utilisé par WordPress pour afficher des contenus spécifiques; ces contenus sont atteints par l&#8217;URL de la page demandée; par exemple l&#8217;URL http://www.monsite.fr/?page_id=4 chargera le template page.php.</p>
<h3>La template hierarchy (simplifiée)</h3>
<p>WordPress utilise un système de hiérarchie de templates pour afficher les contenus du site. Pour un article par exemple il utilisera un template particulier : single.php. Si le template n&#8217;existe pas, il parcourt alors la hiérarchie jusqu&#8217;à trouver le bon template à utiliser. </p>
<p><a href="http://www.arbre-helices.com/wp-content/uploads/2012/03/hierarchy1.jpg" rel="lightbox[457]" title="hierarchy1"><img src="http://www.arbre-helices.com/wp-content/uploads/2012/03/hierarchy1.jpg" alt="" title="hierarchy1" width="500" height="407" class="alignnone size-full wp-image-444" /></a></p>
<h3>La boucle WordPress</h3>
<p>La boucle de WordPress (the Loop) est essentielle puisque c&#8217;est elle qui affichera les contenus du site sur les différentes pages (single, category, index, page,&#8230;). Elle est contextuelle, en effet selon l&#8217;URL elle affichera tous les articles d&#8217;une catégorie ou  un article, etc. </p>
<p><a href="http://www.arbre-helices.com/wp-content/uploads/2012/03/loop.jpg" rel="lightbox[457]" title="loop"><img src="http://www.arbre-helices.com/wp-content/uploads/2012/03/loop.jpg" alt="" title="loop" width="177" height="185" class="alignnone size-full wp-image-445" /></a></p>
<h3>Anatomie de la boucle WordPress</h3>
<p class="comment" >Boucle minimaliste.  </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;!-- Boucle WordPress : The Loop  --&gt;
 <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;h2&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;post&quot;&gt;
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;p&gt;Aucun article trouvé ...&lt;/p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Dans chacune des pages WordPress on a un objet global $wp_query, qui s&#8217;occupe de faire les bonnes requêtes, via les méthodes de cet objet, et en fonction de la page dans laquelle on se trouve. Un tableau contenant les articles est retourné par l&#8217;objet et est sauvegardé dans une variable global $posts.</p>
<p><a href="http://www.arbre-helices.com/wp-content/uploads/2012/03/loop2.jpg" rel="lightbox[457]" title="loop2"><img src="http://www.arbre-helices.com/wp-content/uploads/2012/03/loop2.jpg" alt="" title="loop2" width="177" height="185" class="alignnone size-full wp-image-446" /></a></p>
<h3>Marqueurs de modèle</h3>
<p>On appelle marqueur de modèle les fonctions de WordPress qui permettent d&#8217;appeler d&#8217;autres fichiers ou d&#8217;afficher et personnaliser des contenus. Ces fonctions on été créées pour faciliter le paramétrage d&#8217;un thème WordPress </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
* description : cette fonction renvoie faux si aucun post n'est trouvé dans la requête, 
* sinon, tant qu'il y a des posts elle renvoie les contenus liés au post post par post.
*/</span>
have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">/*
* description : permet de faire l'itération et l'initialisation 
* de la variable $posts dans la boucle while
*/</span>
the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">/*
* description : marqueur de modèle de WordPress
* Ils affichent des informations que l'on peut également personnaliser dans le template, tous
* les marqueurs ci-dessous sont à utiliser à l'INTERIEUR DE LA BOUCLE
*/</span>
the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d/m/Y'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// date de publication de l'article</span>
the_title_attribute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//titre sans html pour le titre du lien</span>
the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//titre de l'article</span>
the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// le contenu de l'article</span>
the_excerpt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// un extrait de l'article</span>
the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// le lien vers l'article </span>
the_author<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//le nom de l'auteur</span>
the_author_posts_link<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//lien vers la page de l'auteur</span>
the_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// lien vers la catégorie de l'article</span>
<span style="color: #339933;">...</span></pre></div></div>

<p>Pour une liste plus détaillée des marqueurs de modèle de WordPress : <a class="link" href="http://codex.wordpress.org/fr:Marqueurs_de_Modele">Marqueurs de modèle</a></p>
<h3>L&#8217;index.php </h3>
<p>Un template WordPress comporte une boucle pour afficher les articles ou contenus du site, des marqueurs de modèle, des fonctions de WordPress, du code HTML . Classiquement, un template est composé d&#8217;inclusion de fichiers get_header(), get_footer(),&#8230; pour inclure les fichiers des parties du site que l&#8217;on retrouve partout. </p>
<p><a href="http://www.arbre-helices.com/wp-content/uploads/2012/03/mytheme_structure_wordpress_liteby-imac4c.jpg" rel="lightbox[457]" title="mytheme_structure_wordpress_lite(by imac4c)"><img src="http://www.arbre-helices.com/wp-content/uploads/2012/03/mytheme_structure_wordpress_liteby-imac4c.jpg" alt="" title="mytheme_structure_wordpress_lite(by imac4c)" width="586" height="822" class="alignnone size-full wp-image-440" /></a></p>
<p class="comment"> On utilisera pour avoir de la documentation sur les différentes fonctions que l&#8217;on utilise pour le développement d&#8217;un thème, le codex de WordPress : <a href="codex.wordpress.org/Function_Reference/" class="link">Function Reference</a></p>
<h3>Code HTML et PHP de l&#8217;index</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;div id=&quot;content&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>     get_template_part<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'loop'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;
&lt;div id=&quot;sidebar&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Détaillons maintenant les différents fichiers que l&#8217;on a inclus :</p>
<h3>get_header()</h3>
<p>header.php </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;title&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_home<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>	
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span> <span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/title&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jquery&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>  
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'html_type'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>; charset=<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'charset'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;meta name=&quot;generator&quot; content=&quot;WordPress <span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'version'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;link rel=&quot;stylesheet&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; type=&quot;text/css&quot; media=&quot;screen&quot; /&gt;
&lt;link rel=&quot;alternate&quot; type=&quot;application/rss+xml&quot; title=&quot;RSS 2.0&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rss2_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;link rel=&quot;alternate&quot; type=&quot;text/xml&quot; title=&quot;RSS .92&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rss_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;link rel=&quot;alternate&quot; type=&quot;application/atom+xml&quot; title=&quot;Atom 0.3&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'atom_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;link rel=&quot;pingback&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pingback_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_head<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;body&gt;
&lt;div id=&quot;main&quot;&gt;
&lt;div id=&quot;banner&quot;&gt;
    &lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
    &lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
     &lt;div id=&quot;search&quot; &gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> get_search_form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/div&gt;
    &lt;div id=&quot;nav&quot;&gt;
    <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_nav_menu<span style="color: #009900;">&#40;</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'theme_location'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'nav'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'menu_id'</span><span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'main-menu'</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;/div&gt;
&lt;/div&gt;&lt;!-- end banner --&gt;</pre></div></div>

<p>On utilise le marqueur de modèle <strong>bloginfo($variable)</strong> pour récupérer un certain nombre de constantes dans la base de données de WordPress : nom du site, calcule de l&#8217;URL du fichier style.css, etc.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jquery&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>   //ajoute la librairie JQuery 
<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stylesheet_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> //calcule l'URL du fichier style dans le template
<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'rss_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> // calcule l'URL du fichier RSS 
<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'pingback_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> //retrolien
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_head<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> //HOOK permettant aux plugins et à WordPress d'ajouter du code
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_search_form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> // moteur de recherche
/*
* Place un menu dans le template, que l'on peut administrer dans l'admin
* de WordPress 
*/
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_nav_menu<span style="color: #009900;">&#40;</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'theme_location'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'nav'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'menu_id'</span><span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'main-menu'</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>get_template_part(&#8216;loop&#8217;) </h3>
<p>Cette fonction permet d&#8217;inclure des fichiers dans les templates. On peut, par exemple, externaliser la boucle générale dans un fichier loop.php : </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
 *  Boucle générale
 */</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;h2 class=&quot;title-home&quot; &gt;Articles récents&lt;/h2&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> 
&lt;div class=&quot;current-post&quot;&gt;
 <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> has_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
             &lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title_attribute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; &gt;
                 <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thumbnail'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
             &lt;/a&gt;
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
            &lt;p class=&quot;date&quot; &gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'d/m/Y'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;/p&gt;
            &lt;h2 class=&quot;title-content&quot; &gt;&lt;a class=&quot;article&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title_attribute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; &gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h2&gt;
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_excerpt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
            &lt;p&gt;&lt;a class=&quot;link&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; &gt;lire la suite...&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;&lt;!-- end current-post --&gt;
&nbsp;
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span>  <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
    &lt;h2&gt;Contenu introuvable...&lt;/h2&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Pour plus d&#8217;information sur les marqueurs de modèle utilisés ci-dessous on ira sur le codex. </p>
<h3>get_sidebar()</h3>
<p>Dans la sidebar tout va dépendre du site que l&#8217;on développe, en général, on y place des menus secondaires, un moteur de recherche, des widgets, etc. </p>

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

<h3>functions.php</h3>
<p>WordPress centralise la configuration du thème et sa personnalisation dans un fichier particulier : functions.php. Ce dernier doit être placé dans le dossier du thème développé. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
 * description : fichier de configuration du thème
 * auteur : Antoine
 * 
 */</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* -------- support theme -------*/</span>
add_theme_support<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'menus'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  <span style="color: #666666; font-style: italic;">//ajoute la gestion admin des menus</span>
&nbsp;
add_theme_support<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post-formats'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'gallery'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//post-formats tags particuliers pour les posts</span>
&nbsp;
add_theme_support<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post-thumbnails'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// miniature pour les posts</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/* -------- menu -------*/</span>
&nbsp;
register_nav_menus<span style="color: #009900;">&#40;</span>
        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'nav'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'menu principal'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'nav_footer'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'menu dans le footer'</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;">/* ------------ custom post type ----------- */</span>
&nbsp;
<span style="color: #b1b100;">require_once</span> <span style="color: #009900;">&#40;</span>ABSPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'wp-content/themes/mon_theme/inc/custom_type.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/* ------------ shortcode ----------- */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> shortcode_youtube<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$atts</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span> shortcode_atts<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'height'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">350</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'width'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">640</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$atts</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$out</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'&lt;div id=&quot;youtube&quot;&gt;&lt;object width=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$width</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; height=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$height</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot;&gt;
	&lt;param name=&quot;movie&quot; value=&quot;http://www.youtube.com/v/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?version=3&amp;amp;hl=fr_FR&amp;amp;rel=0&quot;&gt;&lt;/param&gt;
	&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;&lt;/param&gt;
	&lt;embed src=&quot;http://www.youtube.com/v/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$id</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'?version=3&amp;amp;hl=fr_FR&amp;amp;rel=0&quot;
	type=&quot;application/x-shockwave-flash&quot; width=&quot;420&quot; height=&quot;315&quot; allowscriptaccess=&quot;always&quot;
	allowfullscreen=&quot;true&quot;&gt;&lt;/embed&gt;
	&lt;/object&gt;&lt;/div&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$out</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_shortcode<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'youtube'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'shortcode_youtube'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #339933;">...</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>Menus WordPress</h3>
<p>On peut facilement gérer les menus dans l&#8217;admin de WordPress (lien &laquo;&nbsp;menu&nbsp;&raquo; dans &laquo;&nbsp;apparence&nbsp;&raquo;), il faut cependant mettre un peu de code dans le thème pour que tout fonctionne correctement : </p>
<ul class="menu-g square-1">
<li>activation et définition dans le fichier <strong>functions.php</strong></li>
<li>code WordPress à placer dans les templates pour mettre les menus</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
&nbsp;
<span style="color: #009933; font-style: italic;">/**
* description : code à placer dans le thème
*/</span>
<span style="color: #000088;">$args_menu</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'theme_location'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'nav_main'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'container'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'div'</span><span style="color: #339933;">,</span> 
		<span style="color: #0000ff;">'container_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'wrapper-menu'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'menu_id'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'main-menu'</span>
	 <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	wp_nav_menu<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$args_menu</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
 <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
* description : fichier functions.php
*/</span>
<span style="color: #666666; font-style: italic;">/* -------- menu -------*/</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>  <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'register_nav_menu'</span> <span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   register_nav_menus<span style="color: #009900;">&#40;</span>
        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'mon_jolie_menu'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'menu principal'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'nav_footer'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'menu dans le footer'</span>
        <span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p class="comment" >
On peut noter l’utilisation de la fonction function_exists de PHP, elle permet de vérifier si la fonction que l&#8217;on utilise est bien définie. Il faut suivre les recommandations du codex pour son utilisation. En général, on utilise ce genre de fonction PHP pour le développement de plugins ou dans le cas de compatibilité ascendante dans le code.
</p>
<h3>Ajouter un moteur de recherche</h3>
<p>WordPress utilise un template searchform.php que l&#8217;on place dans le template à l&#8217;aide du marqueur : get_search_form() . </p>
<h4>Code du template searchform.php</h4>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;form method=&quot;get&quot; id=&quot;searchform&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/&quot;&gt;
  &lt;div&gt;
    &lt;input type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_search_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;s&quot; id=&quot;s&quot; /&gt;
    &lt;input type=&quot;submit&quot; id=&quot;searchsubmit&quot; class=&quot;bt-search&quot; value=&quot;recherche&quot; /&gt;
  &lt;/div&gt;
&lt;/form&gt;</pre></div></div>

<h3>La sidebar</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
* description : tous les marqueurs de modèle ci-dessous 
* affichent en général des &lt;li&gt;&lt;a&gt; pour les liens vers des contenus
* du site 
*/</span>
wp_list_categories<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$cat_args</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//affiche les liens vers catégories du site</span>
wp_list_pages <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$page_args</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//affiche les liens vers les pages</span>
wp_get_archives<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type=monthly'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//affiche les liens vers les archives par mois</span></pre></div></div>

<h3>Widgetiser une zone du template</h3>
<p>WordPress possède une API de Widgets, ces derniers peuvent se placer dans le site en drag and drop à partir de l&#8217;administration. Pour mettre cette API en place on doit écrire un peu de code : </p>
<ul class="menu-g square-1">
<li>activation dans le fichier <strong>functions.php</strong></li>
<li>code WordPress à placer dans les templates : zones widgetisables</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">//Dans le fichier functions.php
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">/* ---------------- API Widgets ---------------- */</span>
<span style="color: #666666; font-style: italic;">/* bonne pratique : function_exists vérifie que la fonction 
* est définie, disponible dans WordPress
* attention c'est register_sidebars avec un s
 */</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebars'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'name'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Sidebar %d'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//s'incrémente en fonction du nb de zone</span>
	<span style="color: #0000ff;">'id'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'sidebar'</span><span style="color: #339933;">,</span>      <span style="color: #666666; font-style: italic;">//pour WordPress dans l'admin </span>
	<span style="color: #0000ff;">'description'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'zone widgetisée'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;widget&quot;&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'after_widget'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'before_title'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h2 class=&quot;widget-title&quot;&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'after_title'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span> 
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
  <span style="color: #000088;">$num</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">3</span> <span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//définit le nombre de zones widgetisables</span>
  register_sidebars<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</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></pre></div></div>

<p>Dans le fichier sidebar on écrira par rapport à la définition ci-dessus : </p>

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

<p>Si l&#8217;on a que quelques zones widgetisables à définir alors on peut procéder de cette manière, on peut plus facilement personnaliser les choses : </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">//Dans le fichier functions.php
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000088;">$arg_sidebar</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'name'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'widget-sidebar'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'description'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'colonne latérale totalement widgetisable'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;widget&quot; &gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'after_widget'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'before_title'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h2 class=&quot;widget-title&quot;&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'after_title'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	register_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$arg_sidebar</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//deuxième zone widgetisable</span>
	<span style="color: #000088;">$arg_footer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
		<span style="color: #0000ff;">'name'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'widget-footer'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'description'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Dans le footer '</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;div class=&quot;widget&quot; &gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'after_widget'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'before_title'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h2 class=&quot;widget-title&quot;&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'after_title'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	register_sidebar<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$arg_footer</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
//Dans la sidebar.php 
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'widget-sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
//Dans le footer.php
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'widget-footer'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3> add_theme_support</h3>
<p> WordPress dispose d&#8217;options de thème, on notera les plus utilisées : </p>
<p>les miniatures, les post-format et custom-headers<br />
custom-background<br />
editor-style </p>
<h3>Placer une image dans la bannière en background</h3>
<p>On définit dans un premier temps dans le fichier functions.php cette option : </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">//Quelques constantes dans le fichier functions.php</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HEADER_TEXTCOLOR'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'ffffff'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">// couleur du texte sur l'image</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HEADER_IMAGE'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'%s/images/orange.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// %s adresse du template, image par défaut</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HEADER_IMAGE_WIDTH'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">960</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// dimension de l'image à placer dans le header</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'HEADER_IMAGE_HEIGHT'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">150</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*fonction qui placera l'image en background sur le site public
* attention au nom de l'id que l'on utilise il doit se 
* retrouver dans le code HTML du site
*/</span>
<span style="color: #000000; font-weight: bold;">function</span> header_style<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;style type=&quot;text/css&quot;&gt;
        #banner {
            background: url(<span style="color: #000000; font-weight: bold;">&lt;?php</span> header_image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>);
        }
    &lt;/style&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//fonction qui placera dans l'admin l'image </span>
<span style="color: #000000; font-weight: bold;">function</span> admin_header_style<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;style type=&quot;text/css&quot;&gt;
        #headimg {
            width: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> HEADER_IMAGE_WIDTH<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>px;
            height: <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> HEADER_IMAGE_HEIGHT<span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>px;
            background: no-repeat;
        }
    &lt;/style&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*fonction de WordPress pour lui demander 
de prendre en compte les deux fonctions ci-dessus*/</span>
add_custom_image_header<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'header_style'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'admin_header_style'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>tags</h3>
<p>WordPress utilise un template tag.php pour personnaliser l&#8217;affichage des mots clefs, bien sûr s&#8217;il ne trouve pas ce template il parcourt la template hierarchy pour utiliser un autre template. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">//DDEBUT BOUCLE
...
 &lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_tags<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
..
//FIN BOUCLE</pre></div></div>

<h3>Avatar</h3>
<p>WordPress utilise Gravatar, un système de centralisation d&#8217;avatars; il suffit de créer un compte sur le site de gravatar pour créer le sien.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> get_the_author_meta<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//récupère l'avatar de l'auteur </span>
<span style="color: #000088;">$grav_url</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://www.gravatar.com/avatar/&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">md5</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">strtolower</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// récupère l'avatar sur le site gravatar</span></pre></div></div>

<h3>Modèle de page</h3>
<p>On peut définir dans WordPress des modèles spécifiques de page. Une fois le template créé on l&#8217;assigne à une page donnée dans l&#8217;administration. Pour définir ces modèles il faut écrire le code suivant au début du fichier PHP : </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
 * Template Name: présentation
 */</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
...le code du template</pre></div></div>

<p class="comment">Pour avoir le contenu de la page on utilisera la boucle de WordPress. </p>
<h3>Externaliser la boucle</h3>
<p>Si le code de la boucle se retrouve dans plusieurs templates, on peut externaliser la boucle de WordPress dans un fichier loop.php; le nom de ce fichier est libre cependant, on utilisera un nom qui correspond précisément au code que l&#8217;on inclut dans les templates. Une fois que l&#8217;on a créé ce fichier il faut l&#8217;appeler dans les templates à l&#8217;aide du marqueur suivant :</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">/* Pour inclure la boucle dans un template, cette
* fonction récupère le contexte et passe celui-ci à la boucle
* dans le fichier loop.php
*/
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_template_part<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'loop'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
// de même on peut utiliser pour une navigatio</pre></div></div>

<h3>Les commentaires </h3>
<p>Dans le fichier single.php à l&#8217;intérieur de la boucle on placera le code suivant pour appeler le template des commentaires. On personnalisera l&#8217;affichage. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">//BOUCLE debut
<span style="color: #000000; font-weight: bold;">&lt;?php</span> comments_template<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
//BOUCLE fin</pre></div></div>

<p> On peut créer alors un template pour les commentaires : comments.php, dans lequel on placera le code suivant : </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;div class=&quot;wrapper-comments&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> have_comments<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;ul class=&quot;comments&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_list_comments<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;p&gt;Pour l'instant l'article n'a pas de commentaire&lt;/p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> comment_form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/div&gt;&lt;!-- end wrapper-comments --&gt;</pre></div></div>

<h3>Les customs posts types </h3>
<p>Les Customs posts types sont des contenus particuliers (portfolio, livres,&#8230;) qui s&#8217;ajoutent dans l&#8217;administration et que l&#8217;on peut afficher dans le site public. </p>
<p>Pour définir un custom post type dans wordpress on utilise la fonction register_post_type(), que l&#8217;on placera dans le fichier functions.php; on utilisera également un hook pour que WordPress prenne en compte ces customs posts types. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">/* ----- custom post type --------- */</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'create_artichaut_type'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> create_artichaut_type<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$labels</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'artichaut'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'singular_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'artichaut'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'all_items'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'tous les artichauts'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'add_new'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ajouter'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'add_new_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ajouter un artichaut'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'edit'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'éditer'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'edit_item'</span> <span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'éditer un artichaut'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'new_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'nouveau artichaut'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'view'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'voir '</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'view_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'voir un artichaut'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'search_items'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'rechercher un artichaut'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'not_found'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'aucun artichaut trouvé'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'not_found_in_trash'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'pas artichaut dans la poubelle'</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	register_post_type<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'artichaut'</span><span style="color: #339933;">,</span>
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'labels'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$labels</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'public'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//par défaut cpt ne s'affiche pas...</span>
            <span style="color: #0000ff;">'public_queyrable'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//options nécessaires et classiques </span>
            <span style="color: #0000ff;">'show_in_menu'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'query_var'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'rewrite'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'capability_type'</span><span style="color: #339933;">=&gt;</span><span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//tous les utilisateurs peuvent créer des CPT.</span>
            <span style="color: #0000ff;">'has_archives'</span><span style="color: #339933;">=&gt;</span>true<span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// permet de lister les CPT en archives</span>
            <span style="color: #0000ff;">'hierarchical'</span><span style="color: #339933;">=&gt;</span>false<span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//le contenu peut être hiérarchisé, comme les pages ici non</span>
            <span style="color: #0000ff;">'menu_position'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// 5 sous articles, 15 sous pages, 20 sous les pages</span>
            <span style="color: #0000ff;">'supports'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'editor'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'author'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'thumbnail'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'excerpt'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'comments'</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: #009900;">&#125;</span> 
<span style="color: #666666; font-style: italic;">/* ----------- fin cpt ------------- */</span></pre></div></div>

<h3>WP_Query </h3>
<p>Pour personnaliser la boucle WordPress on dispose d&#8217;une classe WP_Query. En effet, en passant des valeurs (arguments) à l&#8217;objet on peut afficher des contenus de manière plus spécifique. Par exemple, ci-dessous on affiche, dans une boucle particulière, tous les customs posts types artichauts : </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Query<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'post_type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'artichaut'</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: #666666; font-style: italic;">// Boucle adaptée à l'objet $query </span>
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">have_posts</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">the_post</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//les marqueurs à l'intérieur de la boucle sont les mêmes	</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;'</span><span style="color: #339933;">;</span>
	the_title<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;/li&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// vide la mémoire de l'objet</span>
wp_reset_postdata<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<h3>Taxonomy</h3>
<p>Pour définir une taxonomie, on utilise register_taxonomy() dans le fichier functions.php. On rappelle qu&#8217;une taxonomie est soit un tag (mot clef) soit une classification (comme les catégories) qui s&#8217;ajoute aux CPT ou posts. Elle permet de définir, par exemple, une navigation horizontale. </p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">//taxo</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'create_poireau_taxonomies'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> create_poireau_taxonomies<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> 
<span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000088;">$labels</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'poireau'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'singular_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'poireau'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'search_items'</span> <span style="color: #339933;">=&gt;</span>  <span style="color: #0000ff;">'rechercher un poireau'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'all_items'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'tous les poireau'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'parent_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'parent poireau'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'edit_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'edit poireau'</span><span style="color: #339933;">,</span> 
    <span style="color: #0000ff;">'update_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'mettre à jour un poireau'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'add_new_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'ajouter un poireau'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'new_item_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'nouveau poireau'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'menu_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Poireau'</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 	
&nbsp;
  register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'poireau'</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'artichaut'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//si false tags, si true catégorie</span>
    <span style="color: #0000ff;">'labels'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$labels</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'show_ui'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'slug'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'poireau'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">//slug dans l'url</span>
  <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>On utilisera le marqueur wp_list_categories() pour afficher la liste les &laquo;&nbsp;taxons&nbsp;&raquo;, il faut se reporter au codex</p>
<h3>Résumé des fichiers utilisés par WordPress</h3>
<p>WordPress utilise un certain nombre de fichiers pour réaliser un thème; pour un thème pas trop complexe on aura par exemple : </p>
<p><a href="http://www.arbre-helices.com/wp-content/uploads/2012/03/files.jpg" rel="lightbox[457]" title="files"><img src="http://www.arbre-helices.com/wp-content/uploads/2012/03/files.jpg" alt="" title="files" width="500" height="500" class="alignnone size-full wp-image-447" /></a></p>
<h3>HOOKS petite introduction</h3>
<p>Les hooks dans WordPress permettent d&#8217;étendre et de personnaliser respectivement les fonctionnalités et les contenus. Il en existe de deux sortes, les actions et les filters.</p>
<h4>Les actions</h4>
<p>Ils sont placés à des points spécifiques du chargement du noyau de l&#8217;application, par exemple sauvegarde d&#8217;un article, chargement de l&#8217;administration (init). </p>
<h4>Les filters</h4>
<p>Ils sont placés lors de la modification des textes, avant l&#8217;enregistrement dans la base de données ou l&#8217;envoi des données au navigateur. </p>
<p><a href="http://www.arbre-helices.com/wp-content/uploads/2012/03/hooks.jpg" rel="lightbox[457]" title="hooks"><img src="http://www.arbre-helices.com/wp-content/uploads/2012/03/hooks.jpg" alt="" title="hooks" width="500" height="500" class="alignnone size-full wp-image-449" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.arbre-helices.com/2012/03/22/developpez-un-theme-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

