<?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>piouPiouM&#039;s dev&#187; Archives pour le tag recherche – piouPiouM&#039;s dev</title>
	<atom:link href="http://pioupioum.fr/tag/recherche/feed/" rel="self" type="application/rss+xml" />
	<link>http://pioupioum.fr</link>
	<description>Bloc-note d&#039;un développeur web</description>
	<lastBuildDate>Thu, 29 Jul 2010 16:47:44 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>WordPress&#160;: récupération avancée des images d&#8217;un article</title>
		<link>http://pioupioum.fr/outils-astuces/wordpress-recuperation-avancee-images-article.html</link>
		<comments>http://pioupioum.fr/outils-astuces/wordpress-recuperation-avancee-images-article.html#comments</comments>
		<pubDate>Tue, 15 Sep 2009 00:11:27 +0000</pubDate>
		<dc:creator>piouPiouM</dc:creator>
				<category><![CDATA[Outils, trucs et astuces]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[media]]></category>
		<category><![CDATA[recherche]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://pioupioum.fr/?p=245</guid>
		<description><![CDATA[De nombreux thèmes WordPress proposent, via un champ personnalisé, une gestion des miniatures à afficher sur la page d&#8217;accueil. Mais pourquoi contraindre ses rédacteurs à cette manipulation, qui, il faut le dire, est relativement lourde,surtout pour le néophyte1. Le plus simple serait de recourir dans son thème à une fonction qui automatiserait la recherche de [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><p>De nombreux thèmes WordPress proposent, <em>via</em> un <strong>champ personnalisé</strong>, une gestion des miniatures à afficher sur la page d&#8217;accueil. Mais pourquoi contraindre ses rédacteurs à cette manipulation, qui, il faut le dire, est <strong>relativement lourde</strong>,surtout pour le néophyte<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>. Le plus simple serait de recourir dans son thème à une fonction qui automatiserait la recherche de l&#8217;image à afficher en tant que thumbnail.</p>

<p>Évidemment, nous pouvons trouver au détour du web des fonctions <a href="http://www.wprecipes.com/how-to-get-the-first-image-from-the-post-and-display-it" title="How to: Get the first image from the post and display it">au code douteux</a><sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup> qui vont se contenter de chercher la première image dans le contenu du billet.</p>

<p>Pourquoi ne pas étendre (et améliorer tant que nous y sommes =) ce type de fonction afin d&#8217;obtenir un outil de <strong>recherche d&#8217;images</strong> au sein d&#8217;un billet&#160;? C&#8217;est ce que je vous propose ici.
<span id="more-245"></span></p>

<h2 id="toc">Table des matières</h2>

<ol>
<li><a href="#telecharger">Code source</a></li>
<li><a href="#fonctionnement">Fonctionnement</a></li>
<li><a href="#exemples">Exemples d&#8217;utilisation</a></li>
<li><a href="#parametres">Liste des paramètres</a></li>
<li><a href="#changelog">Historique des versions et changelog</a></li>
</ol>

<h2 id="telecharger">Code source</h2>

<p>Copiez le code qui suit dans le fichier <code>functions.php</code> de votre thème.</p>

<div class="box file-php">
    <a href="http://assets1.pioupioum.fr/uploads/2009/09/wp-get_post_images.phps" title="Téléchargement du fichier source"><span>Télécharger wp-get_post_images.phps (1.62&#160;Ko)</span></a>
</div>

<script type="text/javascript" src="http://gist.github.com/186392.js"></script>

<h2>Fonctionnement</h2>

<p>Petit retour sur ce code non commenté<sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup>, car, à la lecture aisée.</p>

<h3>Recherche des images</h3>

<p>La fonction <code>get_post_images</code> va effectuer une recherche d&#8217;image(s) dans les images jointes au billet cible si l&#8217;ordre de tri est différent à <strong>natural</strong>. En effet, cette option oblige à parser le contenu dans le sens de lecture de l&#8217;article, qui peut différer de l&#8217;ordre d&#8217;ajout des images dans sa bibliothèque de médias.<br />
Notez que la recherche non naturelle prend directement en compte les ordres de tri.</p>

<p>Si la recherche échoue (ou si l&#8217;ordre de tri est défini à <strong>natural</strong>), le contenu du post est analysé. Seront considérées les images comportants une classe <code>wp-image-(\d+)</code>. Si la recherche s&#8217;avère fructueuse, le tri est appliqué.</p>

<p>Finalement, <code>get_post_images</code> retournera le résultat de la recherche au format spécifié <em>via</em> le paramètre <strong>output</strong>. En cas d&#8217;échec, le booléen <code>false</code> est retourné.</p>

<h3>Quid de la présentation&#160;?</h3>

<p>Le formatage et l&#8217;affichage des données est laissé à la discrétion du développeur. La présentation pourra ainsi évoluer indépendamment de la fonction.</p>

<h2 id="exemples">Exemples d&#8217;utilisation</h2>

<h3>Récupérer les images triées par date (défaut)</h3>

<p>Nous supposons ici que l&#8217;action se déroule dans la boucle puisque qu&#8217;aucun identifiant d&#8217;article n&#8217;a été fourni. Autrement, la valeur de retour sera <em>FALSE</em>.</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> get_post_images<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>


<h3>Liste des images triées par date inverse</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_post_images<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'order=DESC'</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>Liste des images triées par ordre d&#8217;arrivée dans le billet</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_post_images<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'orderby=natural'</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>Récupération de la première image</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_post_images<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'number=1'</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>Récupération de la première image (par contenu, forcé)</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_post_images<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'number=1&amp;orderby=natural'</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>Afficher la miniature de la première image d&#8217;un article</h3>

<p>La fonction <code>first_thumbnail</code> qui suit affichera au format <em>thumbnail</em> la première image du billet ayant pour identifiant <var>$post_id</var>. Si ce dernier est omit, l&#8217;identifiant du billet en cours d&#8217;itération depuis <a href="http://codex.wordpress.org/fr:La_Boucle" title="fr:La Boucle &laquo; WordPress Codex">la boucle</a> sera utilisé.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Display thumb of the first image from a post.
 *
 * @author Mehdi Kabab &lt;http://pioupioum.fr&gt;
 * @copyright Copyright (C) 2009 Mehdi Kabab
 * @license http://www.gnu.org/licenses/gpl.html  GNU GPL version 3 or later
 *
 * @param  array $post_id Optional. Post ID.
 * @return bool False on failure.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> first_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</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: #000088;">$img</span> <span style="color: #339933;">=</span> get_post_images<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;post_id=<span style="color: #006699; font-weight: bold;">$post_id</span>&amp;number=1&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><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> wp_get_attachment_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'thumbnail'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</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></pre></td></tr></table></div>


<h3>Générer une miniature de la première image d&#8217;un article avec timthumb</h3>

<p>La même fonction mais qui fait appel à <a href="http://code.google.com/p/timthumb/" title="timthumb - Project Hosting on Google Code">timthumb</a> pour générer une miniature aux dimensions arbitraires.</p>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Display a dynamic thumbnail of the first image from a post.
 *
 * The defaults are as follows:
 *     'post_id' - Default is null. Post ID.
 *     'h' - Default is null. Thumbnail height.
 *     'w' - Default is null. Thumbnail width.
 *     'q' - Default is null. Thumbnail quality.
 *     'zc' - Default is null. Zoom crop used for generates the thumbnail.
 *
 * @author Mehdi Kabab &lt;http://pioupioum.fr&gt;
 * @copyright Copyright (C) 2009 Mehdi Kabab
 * @license http://www.gnu.org/licenses/gpl.html  GNU GPL version 3 or later
 *
 * @link http://code.google.com/p/timthumb/ Timthumb
 *
 * @param  array $args Optional. Overrides defaults.
 * @return bool False on failure.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> first_thumbnail<span style="color: #009900;">&#40;</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: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$defaults</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'post_id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'h'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'q'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'w'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'zc'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$args</span>    <span style="color: #339933;">=</span> wp_parse_args<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$defaults</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$post_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$img</span>     <span style="color: #339933;">=</span> get_post_images<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;post_id=<span style="color: #006699; font-weight: bold;">$post_id</span>&amp;number=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'post_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">!==</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$img</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$img</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">null</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$post_id</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>in_the_loop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$post_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
            <span style="color: #b1b100;">else</span>
            <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #000088;">$post_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$img</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_parent</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
                <span style="color: #b1b100;">else</span>
                <span style="color: #009900;">&#123;</span>
                    <span style="color: #b1b100;">return</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: #009900;">&#125;</span>
        <span style="color: #000088;">$query</span>     <span style="color: #339933;">=</span> <span style="color: #990000;">http_build_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&amp;amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$thumbnail</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;img src=&quot;%s?src=%s%s&quot; rel=&quot;attachment&quot;%s%s/&gt;'</span><span style="color: #339933;">,</span>
            get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_url'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'display'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/timthumb.php'</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// customize timthumb url</span>
            <span style="color: #000088;">$img</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">guid</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'&amp;amp;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$query</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'w'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot; width=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">{$args['w']}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'h'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">&quot; height=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">{$args['h']}</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #990000;">printf</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;a href=&quot;%s&quot; title=&quot;%s&quot;&gt;%s&lt;/a&gt;'</span><span style="color: #339933;">,</span>
            get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            esc_attr<span style="color: #009900;">&#40;</span>get_the_title<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #000088;">$thumbnail</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">else</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</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></pre></td></tr></table></div>


<p>Ainsi, pour afficher une miniature de 260x120 pixels de la première image de l&#8217;article courant nous utiliserons&#160;:</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> first_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'w=260&amp;h=120'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>


<h2 id="parametres">Liste des paramètres</h2>

<p>Voici la liste des paramètres acceptés par l&#8217;argument <code>$args</code> de la fonction <code>get_post_images</code>&#160;:</p>

<p><strong>number</strong><br />
<em>(integer)</em> <em>(optionnel)</em> Le nombre maximal d&#8217;images à retourner. Par défaut à <em>-1</em>, retourne toutes les images.</p>

<p><strong>order</strong><br />
<em>(string)</em> <em>(optionnel)</em> Ordre de tri. Les valeurs valides sont&#160;:</p>

<ul>
<li><code>'ASC'</code> - Croissant (du plus petit au plus grand). (Par défaut)</li>
<li><code>'DESC'</code> - Décroissant (du plus grand au plus petit).</li>
</ul>

<p><strong>orderby</strong><br />
<em>(string)</em> <em>(optionnel)</em> Ordonner les images par l&#8217;une des valeurs qui suivent&#160;:</p>

<ul>
<li><code>'date'</code> - Trier selon la date de création. (Par Défaut)</li>
<li><code>'post_id'</code> - Trier numériquement par l&#8217;ID des articles.</li>
<li><code>'natural'</code> - Trier selon l&#8217;affichage des images dans le contenu de l&#8217;article.</li>
</ul>

<p><strong>output</strong><br />
<em>(string)</em> <em>(optionnel)</em> Le format de sortie.</p>

<ul>
<li><code>OBJECT</code> - Retourne un tableau d&#8217;objets instances de la classe stdClass. (Par défaut)</li>
<li><code>ARRAY_A</code> - Retourne un tableau associatif (nom des champs => valeurs).</li>
<li><code>ARRAY_N</code> - Retourne un tableau indexé numériquement de la valeur des champs.</li>
</ul>

<p><strong>post_id</strong><br />
<em>(integer)</em> <em>(optionnel)</em> L&#8217;identifiant de l&#8217;article à analyser. Par défaut à <em>NULL</em>, utilise celui du billet courant dans la boucle.</p>

<p><strong>preserve_keys</strong><br />
<em>(boolean)</em> <em>(optionnel)</em> Préserver les clés retournées par l&#8217;API de WordPress, c.-à-d les identifiants des images. Par défaut à <em>FALSE</em>, le tableau résultat est indexé numériquement à partir de 0.</p>

<h2 id="changelog">Historique des versions et changelog</h2>

<h3>1.0.0</h3>

<ul>
<li>Version initiale.</li>
</ul>

<h3 class='related_post_title'>Continuez votre lecture sur des sujets similaires</h3>

<ul class='related_post'><li><a href='http://pioupioum.fr/snippets/wordpress-autoriser-upload-media-format-inconnu.html' title='WordPress : autoriser l&#8217;upload de fichiers au format non-supporté'>WordPress&#160;: autoriser l&#8217;upload de fichiers au format non-supporté</a></li><li><a href='http://pioupioum.fr/outils-astuces/afficher-images-article-page-media.html' title='WordPress : lister les images d&#8217;un article sur une page media'>WordPress&#160;: lister les images d&#8217;un article sur une page media</a></li><li><a href='http://pioupioum.fr/plugins-wordpress/wordpress-jquery-ui-effects.html' title='WordPress jQuery UI Effects'>WordPress jQuery UI Effects</a></li><li><a href='http://pioupioum.fr/snippets/convertir-icone-icns-png.html' title='Convertir une icône ICNS en une image PNG'>Convertir une icône ICNS en une image PNG</a></li><li><a href='http://pioupioum.fr/outils-astuces/faille-wordpress-mot-passe-correctif.html' title='Correctif pour la faille WordPress de réinitialisation de mot de passe'>Correctif pour la faille WordPress de réinitialisation de mot de passe</a></li></ul>

<div class="footnotes">
<hr />
<ol>

<li id="fn:1">
<p>uploader l&#8217;image, récupérer son URL relative donc en supprimer la racine du site, ajouter un champ personnalisé pour y renseigner l&#8217;URL précédemment copiée.&#160;<a href="#fnref:1" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:2">
<p>franchement, que d&#8217;erreurs dans cette fonction qui a pourtant fait du bruit&#160;: la temporisation n&#8217;est d&#8217;aucune utilité, la globale <var>$posts</var> ne sert à rien, une Notice est générée lorsque l&#8217;article ne contient pas d&#8217;image, l&#8217;auteur de la fonction sait qu&#8217;il recherche 1 image alors pourquoi recourir à <code>preg_match_all</code> au lieu d&#8217;un simple <code>preg_match</code>&#160;? C&#8217;est court donc c&#8217;est cool, c&#8217;est ça&#160;? (&#8216;o_o)&#160;<a href="#fnref:2" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:3">
<p>vous pouvez me flageller <img src='http://pioupioum.fr/wp/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> &#160;<a href="#fnref:3" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
<!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://pioupioum.fr/outils-astuces/wordpress-recuperation-avancee-images-article.html/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>
