<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><title>Gleenk Webdesign</title> <link>http://www.gleenk.com</link> <description>Davide De Maestri - Webdesigner</description> <lastBuildDate>Tue, 15 May 2012 18:23:49 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Gleenk-Webdesign" /><feedburner:info uri="gleenk-webdesign" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><image><link>http://www.gleenk.com</link><url>http://www.gleenk.com/wp-content/themes/designpile/images/gl-logo.png</url><title>Gleenk Webdesign</title></image><item><title>Elencare gli utenti del tuo sito con WordPress</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/ei2mHKVkaHY/</link> <comments>http://www.gleenk.com/elencare-gli-utenti-del-tuo-sito-con-wordpress/#comments</comments> <pubDate>Tue, 15 May 2012 05:30:03 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[CMS]]></category> <category><![CDATA[Webmaster]]></category> <category><![CDATA[wordpress]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=2140</guid> <description><![CDATA[Creiamo un listato di utenti iscritti al sito WordPress mostrando nome e avatar!]]></description> <content:encoded><![CDATA[<p>In questi giorni mi sono trovato di fronte alla necessità di <strong>creare dei listati degli utenti di un sito realizzato in WordPress</strong>. Frugando su Google ho scoperto che dalla versione 3.0 di WordPress è stata realizzata una classe <code>WP_User_Query()</code> che permette di estrarre i dati in modo rapido ed efficace.<br /> Quello che tuttavia non sono riuscito a trovare era come stampare gli avatar degli utenti e linkare alla <a href="http://codex.wordpress.org/Author_Templates" target="_blank">pagina autore</a>&#8230; Alla fine dopo svariati tentativi sono riuscito a venirne a capo. Vediamo quindi come fare per ottenere il listato con Avatar + Nome + Cognome.</p><p>Nota importante: ho scoperto che, se si crea un nuovo ruolo utilizzando l&#8217;Editor Ruoli Utente, è possibile fare la query passando qualsiasi ruolo e quindi possiamo potenzialmente filtrare qualsiasi utente!</p><h2>Creare una pagina personalizzata</h2><p>Confesso che non ho fatto esperimenti in altre pagine, nel web infatti si consigliava di utilizzare una pagina personalizzata per fare l&#8217;operazione di recupero utenti. Non credo tuttavia che possano sorgere particolari problemi, salvo avere l&#8217;accortezza di &#8220;resettare&#8221; le query del caso (wp_reset_query/wp_reset_postdata).</p><p>Comunque, nell&#8217;esempio ho realizzato una pagina personalizzata:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php <span style="color: #666666; font-style: italic;">/* Template Name: Template Chi siamo */</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><h2>Wp_User_Query per estrarre i dati</h2><p>Ecco lo script completo utilizzato:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt; ?php
// dichiariamo gli argomenti
$args  = array(
// cerca solo gli utenti con ruolo Autore (è qui che dovrete mettere l&quot;eventuale ruolo creato con Role Editor)
&quot;role&quot; =&gt; &quot;Author&quot;,
// order results by display_name
&quot;orderby&quot; =&gt; &quot;display_name&quot;
);
// Creiamo l&quot;oggetto WP_User_Query
$wp_user_query = new WP_User_Query($args);
// Estraiamo i risultati
$authors = $wp_user_query-&gt;get_results();
// Controlliamo che vi siano
if (!empty($authors))
{
	echo &quot;&lt;ul&gt;&quot;;
	// cicliamo tutti gli utenti filtrati
	foreach ($authors as $author)
	{
		// recuperiamo i dati di ognuno
		$author_info = get_userdata($author-&gt;ID); ?&gt;
		&lt;li&gt;
                        //Creiamo un url alla pagina autore della persona (pare che debba avere un post almeno pubblicato per funzionare il link, vi risulta?
			&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>/?author=&lt; ?php print $author_info-&gt;ID ?&gt;&quot;&gt;
&nbsp;
                        // Recuperiamo l&quot;avatar e settiamo la dimensione (quadrata)
			&lt; ?php print get_avatar( $author_info-&gt;user_email,100);?&gt;
                        // Recuperiamo nome e cognome.
			&lt; ?php print $author_info-&gt;first_name ?&gt; &lt; ?php print $author_info-&gt;last_name ?&gt;
			&lt;/a&gt;
		&lt;/li&gt;
	&lt; ?php
	}
	echo &quot;&lt;/ul&gt;&quot;;
} else {
	echo &quot;Nessun autore trovato&quot;;
}
?&gt;&lt;/ul&gt;</pre></div></div><p>Ho inserito i commenti direttamente nel codice in modo da semplificarne la comprensione. Utilizzando la fantomatica wp_reset_query è possibile lanciare più query nella stessa pagina. Infine confermo che l&#8217;esempio riportato funziona anche con i Gravatars <img src='http://www.gleenk.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /><br /> Potete vedere un esempio in cui ho utilizzato il seguente script qui: <a href="http://www.webhouseit.com/chi-siamo/" target="_blank">http://www.webhouseit.com/chi-siamo/</a></p><p>Articoli correlati:<ol><li><a href='http://www.gleenk.com/tecniche-personalizzare-pannello-admin-wordpress/' rel='bookmark' title='10 Tecniche per personalizzare il pannello admin di WordPress'>10 Tecniche per personalizzare il pannello admin di WordPress</a></li><li><a href='http://www.gleenk.com/come-creare-widget-personalizzato-per-wordpress/' rel='bookmark' title='Come creare un widget personalizzato per WordPress'>Come creare un widget personalizzato per WordPress</a></li><li><a href='http://www.gleenk.com/trasferire-blog-wordpress-3-nuovo-dominio/' rel='bookmark' title='Trasferire blog WordPress 3+ in un nuovo dominio'>Trasferire blog WordPress 3+ in un nuovo dominio</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/elencare-gli-utenti-del-tuo-sito-con-wordpress/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.gleenk.com/elencare-gli-utenti-del-tuo-sito-con-wordpress/</feedburner:origLink></item> <item><title>Ruota e sposta le immagini usando solo i CSS3</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/3ow4WQYm3rY/</link> <comments>http://www.gleenk.com/ruota-e-sposta-le-immagini-usando-solo-i-css3/#comments</comments> <pubDate>Thu, 10 May 2012 05:00:57 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[CSS]]></category> <category><![CDATA[animazione]]></category> <category><![CDATA[css3]]></category> <category><![CDATA[transition]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=2135</guid> <description><![CDATA[Sperimentare, ruotare, spostare ed attivare azioni tutto utilizzando i CSS3? E' possibile? Beh pare proprio di sì!]]></description> <content:encoded><![CDATA[<p>Ebbene sì, alla fine ho ceduto alla tentazione e sono andato a cercare di scoprire se esistesse un modo di &#8220;attivare&#8221; un&#8217;azione utilizzando esclusivamente i <strong>CSS3</strong> senza far ricorso a <strong>jQuery</strong>. Così ho scoperto che utilizzando in combinazione la pseudoclasse &#8220;<code>:checked</code>&#8221; e il selettore &#8220;<code>+</code>&#8221; è possibile ottenere quanto stavo cercando e che ora vedremo.</p><p>Premetto che la funzionalità è ancora limitata, ed essendo vincolata a due stati (checked o no) non permette grandi controlli. Tuttavia ecco i due semplici esperimenti che ho fatto utilizzando alcune proprietà esclusive dei CSS3. Perdonerete la totale mancanza di qualsiasi elemento grafico, vero! Sono solo due esperimenti&#8230;</p><p><a title="Esempio di utilizzo pratico dei CSS3" href="http://www.gleenk.com/demo/css/ruota-sposta-trigger" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="Ruotare e spostare immagini con i CSS3" width="120" height="30" /></a></p><p>PS: utilizzate Chrome o Firefox 12+ per riuscire a vedere tutto correttamente!</p><h2>Ruotare un&#8217;immagine al click</h2><p>Il primo esempio è molto carino da vedersi, sicuramente del tutto inutile a livello pratico, ma fa uso della trasformazione CSS3 chiamata &#8220;rotateY&#8221;. Che cosa fa? Semplicemente ruota un oggetto del DOM rispetto all&#8217;asse Y.</p><h3>Il codice HTML</h3><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;animate-wrap&quot;</span>&gt;</span>  
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ani-1&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>Ruota immagine 1
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;animate&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;01.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;640&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;480&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;img1&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>​</pre></div></div><p>Nota fondamentale: L&#8217;oggetto checkbox deve stare immediatamente prima del div &#8220;animate&#8221;. Già, al momento (confesso di non aver cercato a lungo, quindi se avete altre tecniche vi invito a segnalarle nei commenti) è quanto ho trovato per far avvenire la magia. La magia CSS:</p><div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">&nbsp;
<span style="color: #6666ff;">.animate</span> img <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span><span style="color: #993333;">block</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* GENERICHE */</span>
&nbsp;
<span style="color: #6666ff;">.animate-wrap</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> <span style="color: #6666ff;">.animate</span> img <span style="color: #00AA00;">&#123;</span>
    -webkit-transition<span style="color: #00AA00;">:</span> all 0.5s ease-out<span style="color: #00AA00;">;</span>
    -moz-transition<span style="color: #00AA00;">:</span> all 0.5s ease-out<span style="color: #00AA00;">;</span>
    transition<span style="color: #00AA00;">:</span> all 0.5s ease-out<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.animate-wrap</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span><span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">+</span> <span style="color: #6666ff;">.animate</span> img <span style="color: #00AA00;">&#123;</span>
    -webkit-transition<span style="color: #00AA00;">:</span> all 0.5s ease-out<span style="color: #00AA00;">;</span>
    -moz-transition<span style="color: #00AA00;">:</span> all 0.5s ease-out<span style="color: #00AA00;">;</span>
    transition<span style="color: #00AA00;">:</span> all 0.5s ease-out<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* IMMAGINE 1 */</span>
<span style="color: #6666ff;">.animate-wrap</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> <span style="color: #6666ff;">.animate</span> <span style="color: #cc00cc;">#img1</span> <span style="color: #00AA00;">&#123;</span>
    -webkit-transform<span style="color: #00AA00;">:</span> rotateY<span style="color: #00AA00;">&#40;</span>180deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
    -moz-transform<span style="color: #00AA00;">:</span> rotateY<span style="color: #00AA00;">&#40;</span>180deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
    transform<span style="color: #00AA00;">:</span> rotateY<span style="color: #00AA00;">&#40;</span>180deg<span style="color: #00AA00;">&#41;</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div><p>Le prime due proprietà mi servivano per dare a tutte le animazioni la stessa durata. 0.5 secondi con effetto ease-out in uscita. Il &#8220;trucco&#8221; però avviene nell&#8217;ultima parte. E&#8217; qui infatti che si dice al browser: prendi l&#8217;immagine con id &#8220;<code>img1</code>&#8221; che sta dentro al div con classe &#8220;<code>.animate</code>&#8221; che si trova &#8220;<code>+</code>&#8221; immediatamente dopo il checkbox. Ma fai tutto ciò quando &#8220;spunti&#8221; il checkbox! Et voilà, la magia si realizza! Non ho ancora capito perchè ritorni da solo allo stato di partenza se tolgo la spunta. Ma tant&#8217;è, ci piace così no?</p><h2>Spostare un&#8217;immagine al click: usiamo i keyframes</h2><p>I keyframes sono il futuro prossimo del CSS. Praticamente sono una sorta di timeline (si come quella di flash) che permette di controllare le animazioni nel tempo. Vi consiglio di buttare un occhio a <a href="http://www.webhouseit.com/2012/04/css3-transizioni-e-animazioni/" target="_blank">questo articolo</a> che abbiamo pubblicato di recente su Webhouse, per approfondire un po&#8217; la questione. Ma tornando a bomba sui nostri esempi&#8230; Ecco come fare per spostare un&#8217;immagine utilizzando solo codice CSS:</p><h3>Il codice HTML</h3><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;animate-wrap&quot;</span>&gt;</span>  
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ani-2&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>Sposta immagine 2
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;animate&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">img</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;02.jpg&quot;</span> <span style="color: #000066;">width</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;640&quot;</span> <span style="color: #000066;">height</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;480&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;img2&quot;</span><span style="color: #66cc66;">/</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>​</pre></div></div><p>ed il CSS che si occupa di &#8220;spostare&#8221; l&#8217;immagine utilizzando una transizione.</p><div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/* KEYFRAMES PER IMMAGINE 2 */</span>
<span style="color: #a1a100;">@-webkit-keyframes mymove {</span>
	<span style="color: #933;">0%</span>   <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #933;">50%</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #933;">100%</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #a1a100;">@-moz-keyframes mymove {</span>
	<span style="color: #933;">0%</span>   <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #933;">50%</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #933;">100%</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #a1a100;">@-ms-keyframes mymove {</span>
	<span style="color: #933;">0%</span>   <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #933;">50%</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #933;">100%</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #a1a100;">@-keyframes mymove {</span>
	<span style="color: #933;">0%</span>   <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #933;">50%</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
	<span style="color: #933;">100%</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* IMMAGINE 2 */</span>
<span style="color: #6666ff;">.animate-wrap</span> input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span><span style="color: #ff0000;">&quot;checkbox&quot;</span><span style="color: #00AA00;">&#93;</span><span style="color: #3333ff;">:checked </span><span style="color: #00AA00;">+</span> <span style="color: #6666ff;">.animate</span> <span style="color: #cc00cc;">#img2</span> <span style="color: #00AA00;">&#123;</span>
    -webkit-animation<span style="color: #00AA00;">:</span>mymove 1s <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
    -moz-animation<span style="color: #00AA00;">:</span>mymove 1s <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
    animation<span style="color: #00AA00;">:</span>mymove 1s <span style="color: #993333;">normal</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div><p>Come vedete prima dobbiamo dichiarare nell&#8217;arco di 1 secondo, in che stato si troverà il nostro oggetto del DOM. Al 50% dell&#8217;animazione si troverà spostato di 200px a sinistra(dichiara un position:relative o absolute se no non si sposta. Sì okay, è una considerazione niubba ma meglio farla <img src='http://www.gleenk.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> ).<br /> Note: il nome dell&#8217;animazione lo scegliamo noi. Quindi &#8220;mymove&#8221; può essere pippo, pluto o paperino! Idem per la durata e le %. Ovviamente il 50% di 1 secondo sono 0.5 secondi. Per il resto mi sembra tutto intuitivo, non resta che sbizzarrirsi! Magari con qualche esempio più creativo del mio :S<br /> E&#8217; semplicemente fantastico no?</p><p><a title="Esempio di utilizzo pratico dei CSS3" href="http://www.gleenk.com/demo/css/ruota-sposta-trigger" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="Ruotare e spostare immagini con i CSS3" width="120" height="30" /></a></p><p>Articoli correlati:<ol><li><a href='http://www.gleenk.com/realizzare-carte-animate-con-i-css3/' rel='bookmark' title='Realizzare carte animate con Transizioni e Animazioni CSS3'>Realizzare carte animate con Transizioni e Animazioni CSS3</a></li><li><a href='http://www.gleenk.com/semplice-menu-tendina-discesa-jquery/' rel='bookmark' title='Semplice menu a tendina dropdown con jQuery'>Semplice menu a tendina dropdown con jQuery</a></li><li><a href='http://www.gleenk.com/la-pseudo-classe-target-css3/' rel='bookmark' title='Lo pseudo selettore :target | CSS3'>Lo pseudo selettore :target | CSS3</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/ruota-e-sposta-le-immagini-usando-solo-i-css3/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.gleenk.com/ruota-e-sposta-le-immagini-usando-solo-i-css3/</feedburner:origLink></item> <item><title>WordPress: Evitare post duplicati in loop multipli</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/7MUsgT8geLg/</link> <comments>http://www.gleenk.com/wordpress-evitare-post-duplicati-loop-multipli/#comments</comments> <pubDate>Tue, 03 Apr 2012 05:30:33 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[CMS]]></category> <category><![CDATA[wordpress]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=2116</guid> <description><![CDATA[Un piccolo accorgimento per evitare post duplicati all'interno di 2 loops di Wordpress. Vediamo come fare!]]></description> <content:encoded><![CDATA[<p>Sviluppando un tema per WordPress da zero ci si ritrova in molte situazioni a dover gestire loop multipli. In questi casi, oltre a dover porre attenzione a &#8220;resettare&#8221; i loop (usando funzioni come <a href="http://codex.wordpress.org/Function_Reference/wp_reset_postdata" target="_blank">wp_reset_postdata()</a> o <a href="http://codex.wordpress.org/Function_Reference/wp_reset_query" target="_blank">wp_reset_query()</a>), può sorgere la necessità di evitare che lo stesso post/contenuto venga replicato all&#8217;interno dei 2 loops in considerazione.<br /> Prendiamo ad esempio la classica homepage di un blog. In alto abbiamo uno slider con i primi 3 articoli e sotto un listato di tutti gli altri. Come potremmo fare per evitare che vi siano dei doppioni nei due loop?</p><h2>Evitiamo i duplicati con un trick</h2><p>Il semplice trucco per evitare che i post vengano duplicati tra i loops è quello di memorizzare l&#8217;ID del post in questione all&#8217;interno del primo loop e verificarne l&#8217;esistenza (e quindi determinarne l&#8217;esclusione)  nel loop successivo:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php <span style="color: #000088;">$my_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: #0000ff;">'category_name=evidenza&amp;posts_per_page=1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_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;">$my_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: #000088;">$non_duplicare</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: #666666; font-style: italic;">//Questo è il trick</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;!--</span> Fai le tue azioni dentro al loop <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div><p>Ora che l&#8217;ID è memorizzato nella variabile $non_duplicare, aggiungiamo un controllo nel secondo loop. Scriveremo qualcosa di simile a ciò:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php <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: #b1b100;">if</span><span style="color: #009900;">&#40;</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: #000088;">$non_duplicare</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Questo è il trick</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #339933;">&lt;!--</span> Fai le tue azioni dentro al loop <span style="color: #339933;">--&gt;</span>
<span style="color: #339933;">&lt;</span> ?php <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</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>Se l&#8217;ID del post corrisponde a quello memorizzato allora non considerarlo e vai avanti nell&#8217;estrazione degli altri post.<br /> Tutto molto semplice no?</p><p>Articoli correlati:<ol><li><a href='http://www.gleenk.com/wordpress-loop-corretto-non-sbagliare/' rel='bookmark' title='WordPress Loop Snippets &#8211; Partire col piede giusto'>WordPress Loop Snippets &#8211; Partire col piede giusto</a></li><li><a href='http://www.gleenk.com/wordpress-templates-differenti-articoli/' rel='bookmark' title='Templates differenti per articoli diversi in WordPress'>Templates differenti per articoli diversi in WordPress</a></li><li><a href='http://www.gleenk.com/paginazione-categorie-personalizzate-wordpress/' rel='bookmark' title='Paginazione di categorie personalizzate in WordPress'>Paginazione di categorie personalizzate in WordPress</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/wordpress-evitare-post-duplicati-loop-multipli/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <feedburner:origLink>http://www.gleenk.com/wordpress-evitare-post-duplicati-loop-multipli/</feedburner:origLink></item> <item><title>Confrontare la data odierna in Javascript</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/S6fkaA6yc4k/</link> <comments>http://www.gleenk.com/confrontare-data-odierna-javascript/#comments</comments> <pubDate>Fri, 30 Mar 2012 18:27:22 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=2108</guid> <description><![CDATA[Impostare rapidamente un confronto tra due date in Javascript. Vediamo come fare utilizzando l'oggetto Date().]]></description> <content:encoded><![CDATA[<p>Esistono situazioni in cui, senza ricorrere a funzioni server-side, sia sufficiente gestire un <strong>confronto tra date utilizzando Javascript</strong>. Vediamo come confrontare, velocemente, la data odierna con una preimpostata. Seppur sia un argomento trattato all&#8217;alba dei tempi, una rinfrescata potrebbe tornare utile <img src='http://www.gleenk.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> Per farlo utilizzeremo l&#8217;oggetto <a href="http://www.devguru.com/technologies/ecmascript/quickref/date.html" target="_blank">Date</a> e la funzione <a href="http://www.w3schools.com/jsref/jsref_gettime.asp" target="_blank">getTime()</a>.</p><h2>La funzione Javascript di confronto</h2><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> dateCompare<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> preimpostata <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #CC0000;">2092</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">3</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #006600; font-style: italic;">//30 APRILE 2092</span>
	<span style="color: #003366; font-weight: bold;">var</span> oggi <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> Date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> diff <span style="color: #339933;">=</span> preimpostata.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>  <span style="color: #339933;">-</span> oggi.<span style="color: #660066;">getTime</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//Se la data preimpostata è già passata</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>diff<span style="color: #339933;">&lt;</span> <span style="color: #339933;">=</span><span style="color: #CC0000;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;La data è già passata!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #006600; font-style: italic;">//Se la data preimpostata non è ancora passata</span>
	<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000066;">alert</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;Non è ancora passata la data!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></pre></div></div><p>Con il codice mostrato stiamo eseguendo le seguenti operazioni:</p><ul><li>Imposto una data &#8220;traguardo&#8221; e la memorizzo nella variabile &#8220;preimpostata&#8221;. Ricordiamoci che la numerazione dei mesi in Javascript parte da 0 e non da uno. Quindi Gennaio corrisponde al mese numero 0.</li><li>Memorizzo in una variabile &#8220;oggi&#8221; la data odierna del pc utilizzando l&#8217;oggetto Date.</li><li>Il metodo getTime() restituisce il numero di millisecondi trascorsi tra il 1 Gennaio 1970 e la data di riferimento. Nel nostro caso quindi saranno rispettivamente la data odierna e il 30 Aprile 2092.</li><li>Se questa differenza è minore o uguale a zero (e quindi la data preimpostata è passata), fai un&#8217;azione altrimenti fanne un&#8217;altra</li></ul><p>Come possiamo vedere è tutto molto semplice. Utilizzando la funzione setFullYear() avremmo potuto anche fare il confronto diretto tra le due date senza passare per i &#8220;millisecondi&#8221;. Altri metodi utili dell&#8217;oggetto <code>Date()</code> per la gestione delle date sono:</p><ul><li>getHours() &#8211; Per ottenere l&#8217;ora</li><li>getMinutes() &#8211; Per ottenere i minuti</li><li>getSeconds() &#8211; Per ottenere i secondi</li><li>getYear() &#8211; Per ottenere l&#8217;anno</li><li>getFullYear() &#8211; Per ottenere l&#8217;anno a 4 cifre</li></ul><p>Per la realizzazione di un orologio, ricordo ancora che utilizzando un linguaggio client-side possiamo recuperare solamente l&#8217;orario del PC dell&#8217;utente, vi rimando a questo semplice esempio: <a href="http://www.w3schools.com/js/tryit.asp?filename=tryjs_timing_clock" target="_blank">Javascript Time Clock</a>.</pre><p>Articoli correlati:<ol><li><a href='http://www.gleenk.com/simulare-fonte-di-luce-dinamica-in-javascript/' rel='bookmark' title='Simulare una fonte di luce dinamica in JavaScript'>Simulare una fonte di luce dinamica in JavaScript</a></li><li><a href='http://www.gleenk.com/estrazione-numeri-casuali-compresi-tra-due-valori-jquery-javascript/' rel='bookmark' title='Estrazione di numeri casuali compresi tra due valori in jQuery/Javascript'>Estrazione di numeri casuali compresi tra due valori in jQuery/Javascript</a></li><li><a href='http://www.gleenk.com/jquery-load-azioni-nella-stessa-pagina/' rel='bookmark' title='jQuery load per eseguire più azioni rimanendo nella stessa pagina'>jQuery load per eseguire più azioni rimanendo nella stessa pagina</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/confrontare-data-odierna-javascript/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.gleenk.com/confrontare-data-odierna-javascript/</feedburner:origLink></item> <item><title>jQuery news spotSlider v2.0</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/9ljoGufmwe4/</link> <comments>http://www.gleenk.com/jquery-news-spot-slider-v2/#comments</comments> <pubDate>Sun, 11 Mar 2012 05:00:29 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=1717</guid> <description><![CDATA[Torna il jQuery News Slider by gleenk nella versione 2.0 rivisto e finalmente corretto nei suoi bugs :D]]></description> <content:encoded><![CDATA[<p><a href="http://www.gleenk.com/demo/jquery/news-spot-slider-v2/"><img src="http://www.gleenk.com/wp-content/uploads/2011/09/jquery-news-slider-v2.jpg" alt="jQuery news slider" title="jQuery news spotSlider v2.0 - gleenk" width="620" height="300" class="alignnone size-full wp-image-1720" /></a></p><p><span style="color:#ad0303; font-weight:bold;">11/03/12 &#8211; Il codice è stato ripulito e tutti i bugs relativi allo spostamento sono stati finalmente risolti</span></p><p>A grande richiesta, con oltre 650 download per la <a href="http://www.gleenk.com/demo/jquery/news-spot-slider-v1/" rel="nofollo">versione 1.0</a>, è finalmente disponibile la <strong>versione 2.0 del jQuery news spotSlider</strong> by Gleenk.</p><p><a href="http://www.gleenk.com/demo/jquery/news-spot-slider-v2/"><img class="alignnone size-full wp-image-1258" title="Download" src="http://www.gleenk.com/wp-content/uploads/2011/05/dload.png" alt="Download jQuery spotSlider v2.0" width="153" height="42" /></a></p><h2>Un carousel per le news!</h2><p>In primis: tutte le vecchie <strong>funzionalità del carousel sono state mantenute</strong>! Ti invito quindi, se non l&#8217;avessi già fatto, a leggere l&#8217;<a href="http://www.gleenk.com/jquery-news-spot-slider/" rel="nofollow">articolo relativo al jQuery newsSpot slider v1.0 </a>in cui vengono illustrate passo passo. In seguito invece illustrerò brevemente le modifiche apportate.<br /> Anticipo fin d&#8217;ora che anche il supporto per i browser è rimasto invariato in modo che non si perdesse nessuna fetta di utenza!</p><h2>3 novità per la versione 2.0</h2><p>Sono tre le novità introdotte, su vostra richiesta, nella versione 2.0. Vediamole 1 ad 1 analizzando brevemente il codice jQuery che è stato necessario implementare:</p><h3>1. Temporizzatore con stati play/pause</h3><p>Attraverso un semplice pulsante play/pause è ora possibile automatizzare lo scorrimento delle news con un tempo stabilito da noi!<br /> Per quanto riguarda il codice html è stato sufficiente aggiungere un link e posizionarlo all&#8217;interno dello slider.</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">   <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:void(0)&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;toggleTime&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;tpause&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Play/Pause&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div><p>In jQuery utilizziamo la funzione <a href="http://api.jquery.com/toggle/" target="_blank">toggle()</a> per far sì che ad ogni click venga azionato o disattivato il timer e, allo stesso tempo, venga effettuato lo switch dell&#8217;immagine di background.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#toggleTime&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toggle</span><span style="color: #009900;">&#40;</span>
	<span style="color: #006600; font-style: italic;">//click in stato di pausa</span>
	  <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		stopTimer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tpause&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tplay&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	  <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
&nbsp;
	  <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		startTimer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tplay&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;tpause&quot;</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><p>La <strong>gestione del temporizzatore</strong> invece è affidata alle funzioni javascript <a href="http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/" title="temporizzatori in javascript" target="_blank">setInterval() e clearInterval()</a> che servono per lanciare e fermare delle funzioni ad intervalli regolari. In questo caso l&#8217;azione da ripetere sarà il semplice click sulla freccia destra! (ps: ricordatevi l&#8217;unbind per <a href="http://www.gleenk.com/jquery-bind-unbind-prevenire-click-multipli/" target="_blank">evitare i click multipli</a>!)</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//timer autoslide</span>
	<span style="color: #003366; font-weight: bold;">var</span> myTimer<span style="color: #339933;">;</span>
	<span style="color: #003366; font-weight: bold;">var</span> timerbis<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> startTimer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		myTimer <span style="color: #339933;">=</span> window.<span style="color: #660066;">setInterval</span><span style="color: #009900;">&#40;</span> <span style="color: #003366; 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: #009900;">&#40;</span><span style="color: #3366CC;">'.news_slider-right'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                        $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.news_slider-right'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unbind</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> intTmp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> stopTimer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		window.<span style="color: #660066;">clearInterval</span><span style="color: #009900;">&#40;</span>myTimer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		clearTimeout<span style="color: #009900;">&#40;</span>timerbis<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span></pre></div></div><p>Una piccola nota: la variabile <code>intTmp</code> permette di <strong>cambiare l&#8217;intervallo di tempo</strong> entro cui effettuare il cambio di slide. Sarà quindi sufficiente modificare questo parametro all&#8217;inizio dello script (espresso in millisecondi):</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Tempo auto-slide</span>
	<span style="color: #003366; font-weight: bold;">var</span> intTmp <span style="color: #339933;">=</span> <span style="color: #CC0000;">5000</span><span style="color: #339933;">;</span></pre></div></div><h3>2. Freccia di navigazione indietro a scomparsa</h3><p>Nella versione precedente la freccia di navigazione sinistra era sempre visibile, ora invece, quando ci troviamo al punto di partenza, viene <strong>automaticamente rimossa</strong>! Per farlo è stato sufficiente verificare il caso in cui il &#8220;left&#8221; dello slider avesse valore 0. In tal caso, da verificare ad ogni click al termine dello scorrimento, la freccia viene nascosta.</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//controllo posizione per comparsa frecce</span>
	<span style="color: #003366; font-weight: bold;">function</span> checkFrecce<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
	<span style="color: #000066; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>boxUl.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;left&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">==</span><span style="color: #3366CC;">&quot;0px&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.news_slider-left&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #000066; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.news_slider-left&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</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><h3>3. Ritorno automatico al punto di partenza</h3><p>Per concludere, è stato fatto un semplice controllo sulla posizione dello slider affinchè, raggiunto l&#8217;ultimo blocco di 4 news, lo slider torni <strong>automaticamente alla posizione iniziale</strong>. Il controllo implementato è il seguente:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">...
<span style="color: #660066;">boxUl</span>.<span style="color: #000066;">stop</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">animate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>left<span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;0px&quot;</span><span style="color: #009900;">&#125;</span>
...</pre></div></div><h3>Note d&#8217;uso e conclusioni</h3><p>Questo script, come il precedente è rilasciato sotto licenza CC Non Commerciale. Sarei lieto di poter vedere i siti in cui implementerete lo script per poterli condividere con tutti i lettori. Infine, se qualcuno riscontrasse dei bug o avesse delle migliorie da apportare&#8230; fatevi avanti!</p><p><a href="http://www.gleenk.com/demo/jquery/news-spot-slider-v2/"><img class="alignnone size-full wp-image-1258" title="Download" src="http://www.gleenk.com/wp-content/uploads/2011/05/dload.png" alt="Download jQuery spotSlider v2.0" width="153" height="42" /></a></p><p>Articoli correlati:<ol><li><a href='http://www.gleenk.com/jquery-news-spot-slider/' rel='bookmark' title='jQuery News Slider &#8211; gleenk spotSlider v1.0'>jQuery News Slider &#8211; gleenk spotSlider v1.0</a></li><li><a href='http://www.gleenk.com/uno-slider-infinito-in-4-righe-jquery/' rel='bookmark' title='Uno slider infinito in 4 righe, con jQuery!'>Uno slider infinito in 4 righe, con jQuery!</a></li><li><a href='http://www.gleenk.com/jquery-bind-unbind-prevenire-click-multipli/' rel='bookmark' title='jQuery bind e unbind, come prevenire click multipli'>jQuery bind e unbind, come prevenire click multipli</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/jquery-news-spot-slider-v2/feed/</wfw:commentRss> <slash:comments>16</slash:comments> <feedburner:origLink>http://www.gleenk.com/jquery-news-spot-slider-v2/</feedburner:origLink></item> <item><title>9 consigli SEO per ottimizzare i titolo delle tue pagine web</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/dqlZMECFvVw/</link> <comments>http://www.gleenk.com/9-consigli-seo-per-ottimizzare-i-titolo-delle-tue-pagine-web/#comments</comments> <pubDate>Tue, 06 Mar 2012 05:00:02 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[SEO - SEM - COPY]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=2083</guid> <description><![CDATA[Il title rappresenta ancora uno dei fattori on-page più importanti quando si parla di SEO. E' un'opportunità importante da non dimenticarsi di sfruttare perchè permette di avere un duplice controllo sui motori e sugli utenti che leggeranno.]]></description> <content:encoded><![CDATA[<p>Il <code>title</code> rappresenta ancora uno dei <a href="http://www.giorgiotave.it/fattori/2011/esperti" target="_blank">fattori on-page</a> più importanti quando si parla di SEO. Idealmente rappresenta il punto del codice in cui descrivere nel modo più conciso ed efficace possibile il concetto espresso dal contenuto della pagina in questione. E&#8217; un&#8217;opportunità importante da non dimenticarsi di sfruttare perchè permette di avere un duplice controllo sui motori e sugli utenti che leggeranno.</p><h2>Pratiche di ottimizzazione del &lt;title&gt;</h2><p>Vediamo quindi 9 rapidi consigli per ricordarsi di controllare che stiamo svolgendo tutto nel modo corretto è migliore possibile!<br /> <img src="http://www.gleenk.com/wp-content/uploads/2012/03/seo-title.jpg" alt="Ottimizzare Title per la SEO" title="Title per la SEO" width="632" height="309" class="alignnone size-full wp-image-2091" /></p><h3><strong>1. Un title per pagina, nel tag &lt;head&gt;</strong></h3><p>Uno degli errori più comuni quando si realizza una pagina web è quello di lasciare il title in bianco, di utilizzarne più di uno per pagina o di inserirlo nel posto sbagliato. Nessuna di queste operazioni è corretta. Inserisci quindi il titolo nel tag &lt;head&gt;, uno per pagina, chiaro ed essenziale.</p><h3><strong>2. Parole chiave ordinate decrescentemente per importanza</strong></h3><p>In questo tag è bene inserire le parole chiavi più importanti in ordine di importanza decrescente. La prima parola quindi ha maggior valore, la seconda un po&#8217; meno e così via.<br /> Quando effettui una ricerca per le parole chiave (ad esempio con l&#8217;<a href="https://adwords.google.com/o/Targeting/Explorer?__c=1000000000&amp;__u=1000000000&amp;ideaRequestType=KEYWORD_IDEAS" target="_blank">Adwords Keyword Tool</a>) controlla sempre il traffico generato dalle parole che stai andando ad utilizzare. Annotati anche il livello di competitività e fai quindi la tua scelta di conseguenza.<br /> Non far diventare questo luogo un&#8217;accozzaglia di parole però, sia chiaro. A nessuno piace leggere una lista di parole insensate.</p><h3><strong>3. Il nome del brand alla fine</strong></h3><p>A causa di quanto appena affermato riguardo alla rilevanza assegnata al &lt;title&gt;, a meno che il nome del tuo brand sia più importante e ricercato del singolo prodotto, metti sempre il nome della tua società alla fine. Per pagine interne al sito, diverse quindi dalla homepage, potresti pensare di omettere il nome del brand.</p><h3><strong>4. Non usare più di 70 caratteri, spazi inclusi</strong></h3><p>I motori di ricerca non apprezzano i titoli lunghi e dopo una certa lunghezza li tagliano azzerando quindi il valore delle keywords. Resta quindi dentro al limite di 70 caratteri per evitare che ciò accade. Ad ogni modo questo numero può oscillare facilmente tra valori prossimi ai 70 quindi, per quanto possibile, cerca di mantenere il numero di parole ridotto.</p><h3><strong>5. Evita di usare le stop-words</strong></h3><p>Le stop-words sono parole che non hanno alcun valore per i motori di ricerca. Solitamente consistono in articoli, verbi ausiliari, congiunzioni, preposizioni e pronomi. Per quanto possibile evita quindi di utilizzarli ricordandoti sempre però che non dovrai trasformare il tuo titolo in un elenco illeggibile per un utente umano. Puoi trovare un elenco di <a href="http://www.ranks.nl/stopwords/italian.html" target="_blank">stopwords su ranks.nl</a>.</p><h3><strong>6. Usa parole chiave rilevanti presenti nel corpo del testo</strong></h3><p>Per ottenere maggio beneficio dal title, è bene che le parole chiave usate rispecchino (e siano presenti) il testo del corpo della pagina. Questo è fondamentale affinchè i motori di ricerca capiscano che il titolo è realmente la sintesi di ciò che l&#8217;utente leggerà.</p><p><strong>7. Titoli diversi per pagine diverse</strong></p><p>In siti ben fatti non dovrebbe mai succedere che lo stesso contenuto sia presente su più pagine (non fosse altro che per evitare penalizzazioni da contenuti duplicati), allo stesso modo lo stesso title non deve mai trovarsi su più pagine. Se perfino google webmaster tools ce lo dice un motivo in fondo ci sarà <img src='http://www.gleenk.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><h3><strong>8. Evita di replicare esattamente lo stesso contenuto del tag h1</strong></h3><p>In modo simile, seppure pare che recentemente Google abbia ridotto l&#8217;importanza di questo tag, l&#8217;h1 svolge la funzione di descrivere il contenuto di una pagina web. Dal momento che si configura come contenitore rilevante di parole chiave è bene che presenti parole chiave ma fornite, possibilmente, in modo leggermente differente dal title.</p><h3><strong>9. Evita il keyword stuffing</strong></h3><p>Non ripetere la stessa parola più volte nel title, è una pratica scorretta e potrebbe facilmente venire penalizzata. Sfrutta quindi più parole, ottimizzale ma non eccedere mai. Uscire dalle penalizzazioni, soprattutto se sei agli inizi dei tuoi studi SEO, potrebbe sarà sicuramente più difficile che entrarci.</p><p><span style="font-size:10px">Ispirato a: <a href="http://searchengineland.com/nine-best-practices-for-optimized-title-tags-111979" target="_blank">&#8220;Nine Best Practices For Optimized title Tags&#8221;</a></span></p><p>Articoli correlati:<ol><li><a href='http://www.gleenk.com/trucchi-seo-ottimizzazione-pagine-facebook/' rel='bookmark' title='Trucchi SEO per l&#8217;ottimizzazione delle pagine Facebook'>Trucchi SEO per l&#8217;ottimizzazione delle pagine Facebook</a></li><li><a href='http://www.gleenk.com/consigli-per-ottimizzare-le-immagini-per-i-motori-di-ricerca/' rel='bookmark' title='Consigli per ottimizzare le immagini per i motori di ricerca'>Consigli per ottimizzare le immagini per i motori di ricerca</a></li><li><a href='http://www.gleenk.com/consigli-per-un-copy-user-e-seo-friendly/' rel='bookmark' title='Consigli per scrivere un copy User e SEO Friendly'>Consigli per scrivere un copy User e SEO Friendly</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/9-consigli-seo-per-ottimizzare-i-titolo-delle-tue-pagine-web/feed/</wfw:commentRss> <slash:comments>2</slash:comments> <feedburner:origLink>http://www.gleenk.com/9-consigli-seo-per-ottimizzare-i-titolo-delle-tue-pagine-web/</feedburner:origLink></item> <item><title>Mobile Web: Settare icone e immagini per il nostro sito mobile</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/9hl9vRTNDlY/</link> <comments>http://www.gleenk.com/icone-immagini-sito-mobile/#comments</comments> <pubDate>Wed, 29 Feb 2012 05:00:17 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[Html]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=2070</guid> <description><![CDATA[Come si imposta un'icona visibile su smartphone per il nostro sito web? E come si ottimizza un'immagine per il display retina? Scopriamolo!]]></description> <content:encoded><![CDATA[<p>Terminata la realizzazione del nostro sito web per mobile, è bene non dimenticarsi di preparare un&#8217;icona in modo da dare un tocco di classe al nostro lavoro. Vediamo quindi come impostare un tag affinchè la nostra icona venga riconosciuta su iOS e Android.</p><p><img src="http://www.gleenk.com/wp-content/uploads/2012/02/settare-icona-mobile.jpg" alt="" title="settare icona mobile" width="615" height="449" class="alignnone size-full wp-image-2073" /></p><p>Nessuno vorrebbe che l&#8217;icona del proprio sito venisse visualizzata come nell&#8217;immagine qui sopra, confondendosi tra tutti gli altri salvataggi. Non curare l&#8217;immagine lascia al titolo l&#8217;unica possibilità di catturare l&#8217;attenzione. Se invece sfruttiamo anche questa piccola possibilità possiamo sperare di fidelizzare maggiormente l&#8217;utente con il nostro brand.</p><p>Settare un&#8217;immagine non per nulla difficile. Creiamo un PNG di 158&#215;158 pixel, ed aggiungiamo dentro <code>&lt;head&gt;</code> il seguente codice HTML:</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;icon&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/icon&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;favicon.png&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;apple-touch-icon&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;images/icon.png&quot;</span><span style="color: #66cc66;">/</span>&gt;</span></pre></div></div><p>Il consiglio è di non utilizzare trasparenze e ricordarsi che i bordi verranno stondati. Evitiamo quindi scritte troppo vicine ai margini.</p><h2>Creare un immagine per il Display Retina</h2><p>Quando realizziamo un sito per mobile potremmo decidere di sfruttare il display retina dell&#8217;iPhone per dare ai suoi utenti una visualizzazione migliore delle nostre immagini. Il meccanismo è semplice ed applicabile solamente alle immagini CSS di background.<br /> Ricordo che per migliorare immagini inserite tramite tag <code>img</code> invece è sufficiente caricare immagini di dimensioni maggiori dello schermo e settare una larghezza del 100% ed un altezza automatica.</p><p>Ma vediamo un esempio che fa al caso nostro tenendo presente che 1px sull&#8217;iPhone corrisponde a 2 pixel retina:</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;editIcon&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
&nbsp;
Nel css invece andremo ad impostare:</pre></div></div><div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#editIcon</span><span style="color: #00AA00;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">16px</span><span style="color: #00AA00;">;</span>
   <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">img/edit.png</span><span style="color: #00AA00;">&#41;</span> <span style="color: #993333;">no-repeat</span><span style="color: #00AA00;">;</span> // L<span style="color: #ff0000;">'immagine avrà una dimensione originale di 32x32pixel
   -webkit-background-size: 16px 16px;
   background-size: 16px 16px;
}</span></pre></div></div><p>L&#8217;immagine con risoluzione 32×32 pixel viene usata per raddoppiare la qualità della risoluzione quando si forza l&#8217;immagine a 16x16px. Ovviamente questo comporta la creazione di immagini più pesanti, di conseguenza sarà opportuno realizzare un CSS apposito per il nostro dispositivo retina in modo da aggirare il problema:</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;only screen and (-webkit-min-device-pixel-ratio: 2)&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;retina.css&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span></pre></div></div><p>Articoli correlati:<ol><li><a href='http://www.gleenk.com/aggiungere-dimensioni-immagini-diversi-post-wordpress/' rel='bookmark' title='Set di dimensioni di immagini diverse per i nostri articoli WordPress'>Set di dimensioni di immagini diverse per i nostri articoli WordPress</a></li><li><a href='http://www.gleenk.com/didascalie-immagini-jquery-hover-animate/' rel='bookmark' title='Didascalie per immagini con jQuery hover e animate'>Didascalie per immagini con jQuery hover e animate</a></li><li><a href='http://www.gleenk.com/aumentare-la-velocita-di-un-sito/' rel='bookmark' title='Aumentare la velocità di un sito'>Aumentare la velocità di un sito</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/icone-immagini-sito-mobile/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://www.gleenk.com/icone-immagini-sito-mobile/</feedburner:origLink></item> <item><title>Uno slider infinito in 4 righe, con jQuery!</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/yyt8atSeQjY/</link> <comments>http://www.gleenk.com/uno-slider-infinito-in-4-righe-jquery/#comments</comments> <pubDate>Mon, 13 Feb 2012 09:53:16 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=2045</guid> <description><![CDATA[E' possibile ruotare ciclicamente ed all'infinito degli oggetti in sole 4 righe di codice? Si! Come sempre grazie a jQuery. Vediamo come fare!]]></description> <content:encoded><![CDATA[<p>Il bello di jQuery è che più lo conosci, e più scopri funzionalità che semplificano la vita. In questo esempio vediamo come, grazie alla funzione <a href="http://api.jquery.com/appendTo/" target="_blank">appendTo()</a> possiamo scombinare gli elementi del DOM e realizzare un mini-slider infinito. Certo, non aspettiamoci di poter fare miracoli&#8230; Quello che mi interessa sottolineare è come, con questa funzionalità, bastino poche righe per realizzare un sistema funzionale e facilmente implementabile in ogni progetto.</p><p><a title="Esempio di rotazione infinita di elementi" href="http://www.gleenk.com/demo/jquery/navigazione-slider-infinito/" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><h2>Let&#8217;s go! E&#8217; tempo di HTML!</h2><p>Bando alle ciance, è tempo di scrivere il nostro codice HTML! Ci servirà davvero poco in termini di elementi del DOM: saranno sufficienti un wrapper che funga da maschera con dei box al suo interno, e due pulsanti di navigazione (avanti ed indietro):</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;slider&quot;</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;wrapper&quot;</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;box&quot;</span>&gt;</span>1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;box&quot;</span>&gt;</span>2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;box&quot;</span>&gt;</span>3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
		<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;box&quot;</span>&gt;</span>4<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
	<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:void(0);&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;prev&quot;</span>&gt;</span>Prev<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span> | <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:void(0);&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;next&quot;</span>&gt;</span>Next<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div><h2>Il codice CSS, il gioco delle maschere</h2><p>Riutilizzando il sistema di maschere già visto per la realizzazione del jQuery News Slider, implementiamo il nostro CSS. Come sempre, quello che riporto è a scopo puramente illustrativo, mi auguro invece che la vostra creatività si sbizzarrisca per realizzare qualcosa di stupefacente!</p><div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#slider</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">420px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #933;">100px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #cc00cc;">#CCC</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span><span style="color: #933;">20px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#slider</span> <span style="color: #6666ff;">.wrapper</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">position</span><span style="color: #00AA00;">:</span><span style="color: #993333;">relative</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">870px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span><span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#slider</span> <span style="color: #6666ff;">.wrapper</span> <span style="color: #6666ff;">.box</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span><span style="color: #993333;">red</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span><span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span><span style="color: #000000; font-weight: bold;">left</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: #933;">10px</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#slider</span> <span style="color: #6666ff;">.wrapper</span> <span style="color: #6666ff;">.box</span><span style="color: #3333ff;">:first-child </span><span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span><span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
	<span style="color: #00AA00;">&#125;</span></pre></div></div><h2>E&#8217; l&#8217;ora di jQuery! Animiamo la rotazione</h2><p>Il codice, che ora spieghiamo, è il seguente:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; 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: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#slider .next&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; 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: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#slider .wrapper .box:first&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">appendTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#slider .wrapper&quot;</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>	
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#slider .prev&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; 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: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#slider .wrapper .box:last&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">prependTo</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#slider .wrapper&quot;</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>	
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>Come possiamo vedere fondamentalmente utilizziamo una riga di codice, che poi ripetiamo per il pulsante next e prev. Grazie alla combinazione delle funzioni <code>appendTo()</code> &#038; <code>prependTo()</code> e dei selettori <code>:first</code> e <code>:last</code> realizziamo la nostra animazione. Le funzioni citate non fanno altro che prelevare l&#8217;elemento del DOM selezionato e spostarlo fisicamente all&#8217;inizio o alla fine del contenitore in questione (.wrapper). I selettori invece ci indicano quale elemento targetizzare. Nel nostro caso il primo o l&#8217;ultimo. E così, con queste semplicissime righe, il gioco è fatto. Stupendo no? <img src='http://www.gleenk.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /></p><p><a title="Esempio di rotazione infinita di elementi" href="http://www.gleenk.com/demo/jquery/navigazione-slider-infinito/" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><p>Articoli correlati:<ol><li><a href='http://www.gleenk.com/accordion-jquery/' rel='bookmark' title='Realizzare un accordion jQuery in 5 righe di codice!'>Realizzare un accordion jQuery in 5 righe di codice!</a></li><li><a href='http://www.gleenk.com/jquery-news-spot-slider/' rel='bookmark' title='jQuery News Slider &#8211; gleenk spotSlider v1.0'>jQuery News Slider &#8211; gleenk spotSlider v1.0</a></li><li><a href='http://www.gleenk.com/jquery-scorrimento-news/' rel='bookmark' title='jQuery per far scorrere le ultime news in 4 righe!'>jQuery per far scorrere le ultime news in 4 righe!</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/uno-slider-infinito-in-4-righe-jquery/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://www.gleenk.com/uno-slider-infinito-in-4-righe-jquery/</feedburner:origLink></item> <item><title>Come creare un widget personalizzato per WordPress</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/cms9YSteIis/</link> <comments>http://www.gleenk.com/come-creare-widget-personalizzato-per-wordpress/#comments</comments> <pubDate>Tue, 31 Jan 2012 05:00:05 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[CMS]]></category> <category><![CDATA[Webmaster]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=2023</guid> <description><![CDATA[Ecco la struttura per realizzare un widget in wordpress perfettamente funzionante! Vediamola!]]></description> <content:encoded><![CDATA[<p><img src="http://www.gleenk.com/wp-content/uploads/2012/01/wordpress-realizzare-widget.jpg" alt="Realizzare un widget con WordPress" title="Realizzare un widget con WordPress" width="620" height="300" class="alignnone size-full wp-image-2035" /><br /> Mentre stiamo realizzando un tema per WordPress, piuttosto che ricorrere a plugin esterni per l&#8217;inserimento di codice PHP (come ad esempio <a href="http://wordpress.org/extend/plugins/php-code-widget/" target="_blank">PHP Code Widget</a>) nelle sidebar, potrebbe tornarci utile realizzare un widget per utilizzare il nostro codice in aree specifiche del sito, senza permettere a terzi (i clienti) di andare a &#8220;toccarlo&#8221; e comprometterne la funzionalità.</p><p>Ci tengo a premettere che non intendo approfondire la tematica  dal punto di vista della programmazione pura, non rientrando nelle mie competenze specifiche, bensì è mio intento indicare un sistema generale e semplice per realizzare un Widget in maniera rapida ed alla portata di tutti, derivato dalla lettura di alcune risorse online e cartacee.</p><h2>Il nostro widget nel file functions</h2><p>Il codice che vediamo va inserito unicamente nel file functions.php del nostro tema. Quello che andremo a fare è realizzare un semplicissimo widget con un titolo, e che stampi una frase. Il nostro widget sarà poi visibile dall&#8217;apposito pannello di WordPress e trascinabile in qualsivoglia <a href="http://codex.wordpress.org/Customizing_Your_Sidebar" target="_blank">sidebar</a>!</p><h3>La struttura funzionale</h3><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span> ?php 
<span style="color: #000000; font-weight: bold;">class</span> myWidget <span style="color: #000000; font-weight: bold;">extends</span> WP_Widget <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> myWidget<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> widget<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$instance</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> update<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$new_instance</span><span style="color: #339933;">,</span> <span style="color: #000088;">$old_instance</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">function</span> form<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$instance</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> my_register_widgets<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	register_widget<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'myWidget'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'widgets_init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_register_widgets'</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>Quella che possiamo vedere qui sopra è la struttura di base che permette al nostro widget di essere riconosciuto e mostrato nel backend di wordpress. Tuttavia così è privo di qualsiasi funzionalità. Sottolineo solo alcuni aspetti che a mio avviso possono interessare. Innanzitutto quello che stiamo andando a fare è estendere la class WP_Widget, ovvero la classe che permette a WP di costruire i widget. In seguito poi abbiamo 4 metodi (funzioni) che permettono di indicare il nome del widget, di eseguirlo realmente, di effettuare correttamente le operazioni di salvataggio e di gestire il campo &#8220;Titolo&#8221; che può essere modificato. Le 4 funzionalità appena elencate fanno riferimento a <code>function myWidget()</code>, <code>function widget()</code>, <code>function update()</code> e <code>function form()</code>.<br /> Infine con la funzione my_register_widgets() (che potete chiamare a vostro piacimento) andiamo a registrare a tutti gli effetti il nostro widget perchè compaia nel backend ed infine lo istanziamo usando <code>add_action()</code>.</p><h3>L&#8217;esempio completo e funzionante</h3><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt; ?php 
class myWidget extends WP_Widget {
	function myWidget() {
		parent::__construct( false, 'Il mio Widget' );
	}
	function widget( $args, $instance ) {
		extract($args);
		echo $before_widget;
		echo $before_title.$instance['title'].$after_title;
&nbsp;
		//DA QUI INIZIA IL WIDGET VERO E PROPRIO
		echo &quot;Ciao Wordpress&quot;;
		//FINE WIDGET
&nbsp;
		echo $after_widget;
	}
	function update( $new_instance, $old_instance ) {
		return $new_instance;
	}
	function form( $instance ) {
		$title = esc_attr($instance['title']); ?&gt;
		&lt;p&gt;&lt;label for=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_field_id</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
		Titolo: &lt;input class=&quot;widefat&quot; id=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-/&gt;</span>get_field_id<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; name=&quot;&lt; ?php echo $this-&gt;get_field_name('title');?&gt;&quot; type=&quot;text&quot; value=&quot;&lt; ?php echo $title; ?&gt;&quot; /&gt;
		&lt;/label&gt;&lt;/p&gt;
		&lt; ?php
	}
}
&nbsp;
function my_register_widgets() {
	register_widget( 'myWidget' );
}
&nbsp;
add_action( 'widgets_init', 'my_register_widgets' );
?&gt;</pre></div></div><p>Che si mostrerà così nel backend:<br /> <img src="http://www.gleenk.com/wp-content/uploads/2012/01/esempio-my-widget.jpg" alt="" title="Esempio widget di base" width="252" height="129" class="aligncenter size-full wp-image-2028" /></p><p>Come già anticipato non è mia competenza addentrarmi troppo nel mondo della programmazione (in particolare ad oggetti in questo caso) quindi lascio al tuo approfondimento personale lo studio di ciò che avviene in ogni passaggio. Ad ogni modo, con il codice sopra proposto in mano, sarà sufficiente (qualora non intendiate fornire ulteriori opzioni modificabili da backend) scrivere il vostro codice php normalmente al posto di:</p><div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//DA QUI INIZIA IL WIDGET VERO E PROPRIO</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Ciao Wordpress&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">//FINE WIDGET</span></pre></div></div><p>Potrete infatti inserirei qui tutto ciò che vi pare, ad esempio usando query_post() potreste estrarre alcuni particolari contenuti e così via. Insomma, la struttura funzionale è questa, poi il cuore dovrete farlo pulsare voi <img src='http://www.gleenk.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p><p>Articoli correlati:<ol><li><a href='http://www.gleenk.com/paginazione-categorie-personalizzate-wordpress/' rel='bookmark' title='Paginazione di categorie personalizzate in WordPress'>Paginazione di categorie personalizzate in WordPress</a></li><li><a href='http://www.gleenk.com/prevenire-email-spam-wordpress-con-antispambot/' rel='bookmark' title='Email di spam in WordPress? Prevenire si può.'>Email di spam in WordPress? Prevenire si può.</a></li><li><a href='http://www.gleenk.com/wordpress-loop-corretto-non-sbagliare/' rel='bookmark' title='WordPress Loop Snippets &#8211; Partire col piede giusto'>WordPress Loop Snippets &#8211; Partire col piede giusto</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/come-creare-widget-personalizzato-per-wordpress/feed/</wfw:commentRss> <slash:comments>3</slash:comments> <feedburner:origLink>http://www.gleenk.com/come-creare-widget-personalizzato-per-wordpress/</feedburner:origLink></item> <item><title>Fancybox e Flowplayer, visualizzare i video in popup!</title><link>http://feedproxy.google.com/~r/Gleenk-Webdesign/~3/tIn0c1iK_jQ/</link> <comments>http://www.gleenk.com/fancybox-e-flowplayer-visualizzare-video-in-popup/#comments</comments> <pubDate>Mon, 23 Jan 2012 05:00:55 +0000</pubDate> <dc:creator>gleenk</dc:creator> <category><![CDATA[Archivio Articoli]]></category> <category><![CDATA[jQuery]]></category><guid isPermaLink="false">http://www.gleenk.com/?p=2009</guid> <description><![CDATA[Visualizziamo i nostri video in fantastici popup utilizzando Fancybox e Flowplayer! Che lo spettacolo abbia inizio!]]></description> <content:encoded><![CDATA[<p><img src="http://www.gleenk.com/wp-content/uploads/2012/01/testata-fancybox-flowplayer.jpg" alt="Testata Fancybox e Flowplayer" title="Fancybox e Flowplayer: video in Popup!" width="620" height="300" class="alignnone size-full wp-image-2018" /><br /> Recentemente mi sono imbattuto con l&#8217;esigenza di includere un video .flv all&#8217;interno del popup di <a href="http://fancyapps.com/fancybox/" target="_blank">Fancybox</a> (uno script jQuery stile lightbox, con funzionalità più avanzate). Seppur lo script offra già di base il supporto all&#8217;integrazione di video Youtube, non c&#8217;è verso di visualizzare un video, se non utilizzando un iframe nel quale integriamo un lettore esterno.</p><p><a title="Utilizzare Fancybox per visualizzare video" href="http://www.gleenk.com/demo/jquery/fancybox-flowplayer/" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><p>Se però abbiamo l&#8217;esigenza di avere il video in pagina &#8220;nascosto&#8221;, siamo costretti a ricorrere ad altri metodi. Ed ecco che, navigando in giro per il web, scopriamo come sia possibile integrare il noto lettore <a href="http://flowplayer.org/" target="_blank">Flowplayer</a> al tanto amato Fancybox. Nel momento in cui scrivo questo articolo garantisco sulla compatibilità totale dei 2 script (in particolare Flowplayer funziona sia con la versione 1.3 che con la versione 2.0+ di Fancybox). L&#8217;unico accorgimento da prendere nel caso si utilizzino versioni di Fancybox differenti, è quello di controllare le funzioni di callback che vengono messe a disposizione.</p><h2>Procuriamoci gli script</h2><p>Per prima cosa, inevitabilmente, scarichiamo Fancybox e Fancyplayer ai link seguenti:<br /> Fancybox: <a href="http://fancyapps.com/fancybox/" target="_blank">http://fancyapps.com/fancybox/</a><br /> Fancyplayer (free): <a href="http://flowplayer.org/download/index.html" target="_blank">http://flowplayer.org/download/index.html</a></p><p>Dopodichè prepariamo la nostra cartella in cui lavoreremo utilizzando la struttura seguente:<br /> <img src="http://www.gleenk.com/wp-content/uploads/2012/01/fancybox-flowplayer-system.jpg" alt="File System Fancybox e Flowplayer" title="Struttura file Fancybox e Flowplayer" width="430" height="130" class="alignnone size-full wp-image-2011" /></p><h2>Prepariamo il codice html da utilizzare</h2><p>Prima di tutto includiamo il css di Fancybox (oltre ad un nostro eventuale foglio stile), jQuery ed i file .js che ci servono:</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fancybox/jquery.fancybox.css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">link</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;style.css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;fancybox/jquery.fancybox.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;flowplayer/flowplayer-3.2.6.min.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">link</span>&gt;</span></pre></div></div><p>Fatto questo prepariamo la semplicissima struttura html:</p><div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;player&quot;</span> data-url<span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://www.gleenk.com/demo/jquery/fancybox-flowplayer/Talbot%20Bay%20-%20Australia%20-%20BBC.flv&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;play-video&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;#player&quot;</span>&gt;</span>Play video<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span></pre></div></div><p>Come vediamo sarà fondamentale avere un attributo in cui inserire l&#8217;url dove si trova il video: per farlo ci siamo avvalsi della proprieta HTML5 data-<em>nome</em>, dove nome è qualsiasi cosa si voglia. Utilizzando jQuery non avremo alcuna difficoltà ad andare a &#8220;pescare&#8221; questo valore. Vi anticipo fin da subito che non avrete problemi di compatibilità cross-browser.<br /> Inoltre impostiamo l&#8217;href del link con il medesimo nome dell&#8217;ID del contenitore del video.</p><h2>jQuery in azione</h2><p>A questo punto non ci resta che scrivere il codice che realizzerà la magia:</p><div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">var</span> url <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#player&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;data-url&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;a#play-video&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">fancybox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>
		 <span style="color: #3366CC;">'scrolling'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
		 <span style="color: #3366CC;">'titleShow'</span><span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">,</span>
		 <span style="color: #3366CC;">'padding'</span>  <span style="color: #339933;">:</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span>
		 <span style="color: #3366CC;">'beforeLoad'</span>  <span style="color: #339933;">:</span> <span style="color: #003366; 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: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#player&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			 $f<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;player&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;flowplayer/flowplayer-3.2.7.swf&quot;</span><span style="color: #339933;">,</span> url<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		 <span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span>
		 <span style="color: #3366CC;">'afterClose'</span>  <span style="color: #339933;">:</span> <span style="color: #003366; 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: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#player&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			 $f<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">unload</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		 <span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div><p>E&#8217; bene sottolineare brevemente alcuni punti. Nel caso che vedete sopra abbiamo utilizzato una variabile url per memorizzare il percorso del video. In questo modo, se avessimo in pagina diversi video, utilizzando opportunamente &#8220;this&#8221; in jQuery potremmo prelevare il video che ci interessa. La variabile url verrebbe infatti cambiata ad ogni click. (Per farlo ricordiamoci di utilizzare delle classi e non ID come nell&#8217;esempio).<br /> Infine è bene precisare che <code>scrolling</code>, <code>titleShow</code>, <code>padding</code> sono proprietà di Fancybox che servono per nascondere spazi, scritte e scrollbar. <code>beforeLoad</code> e <code>afterClose</code> sono invece le 2 callback di cui parlavamo all&#8217;inizio. Sono due funzioni che agiscono prima del caricamento del video e dopo. Saranno queste quelle per cui accertarsi che la sintassi non sia cambiata nel corso di future versioni!</p><h2>Compatibilità con i browser</h2><ul> Il seguente sistema è stato testato e ne è stata accertata la funzionalità sui seguenti browser:</p><li>Mozilla Firefox (qualsiasi versione moderna)</li><li>Chrome (qualsiasi versione moderna)</li><li>Opera (qualsiasi versione moderna)</li><li>Internet Explorer 7+</li></ul><p><a title="Utilizzare Fancybox per visualizzare video" href="http://www.gleenk.com/demo/jquery/fancybox-flowplayer/" target="_blank"><img class="alignnone size-full wp-image-264" title="demo" src="http://www.gleenk.com/wp-content/uploads/2010/06/demo.jpg" alt="tasto per vedere la demo del tutorial" width="120" height="30" /></a></p><p>Articoli correlati:<ol><li><a href='http://www.gleenk.com/html5-tag-video/' rel='bookmark' title='HTML5 tag video'>HTML5 tag video</a></li><li><a href='http://www.gleenk.com/dollaro-invece-jquery-in-wordpress/' rel='bookmark' title='Usare ‘$’ invece di ‘jQuery’ in WordPress'>Usare ‘$’ invece di ‘jQuery’ in WordPress</a></li><li><a href='http://www.gleenk.com/stilizzare-campi-input-file-jquery/' rel='bookmark' title='Stilizzare campi input file con jQuery'>Stilizzare campi input file con jQuery</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://www.gleenk.com/fancybox-e-flowplayer-visualizzare-video-in-popup/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <enclosure url="http://www.gleenk.com/demo/jquery/fancybox-flowplayer/Talbot%20Bay%20-%20Australia%20-%20BBC.flv" length="7665763" type="video/x-flv" /> <feedburner:origLink>http://www.gleenk.com/fancybox-e-flowplayer-visualizzare-video-in-popup/</feedburner:origLink></item> </channel> </rss>

