<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Johan de Bruin &#187; Wordpress</title>
	<atom:link href="http://www.johandebruin.com/c/wordpress-programacion/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.johandebruin.com</link>
	<description>Programación en php, tutorial de api wordpress y posicionamiento en buscadores seo.</description>
	<lastBuildDate>Sun, 05 Feb 2012 15:18:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Crear widget exportable a otras páginas web con el contenido de tu wordpress</title>
		<link>http://www.johandebruin.com/crear-widget-exportable-a-otras-paginas-web-con-el-contenido-de-tu-wordpress/</link>
		<comments>http://www.johandebruin.com/crear-widget-exportable-a-otras-paginas-web-con-el-contenido-de-tu-wordpress/#comments</comments>
		<pubDate>Sat, 17 Sep 2011 11:02:12 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=740</guid>
		<description><![CDATA[Para crear el widget hay 2 pasos fundamentales. Crear un canal RSS con el contenido que deseas exportar Crear el widget, puedes usar uno de las muchas aplicaciones online disponibles o simplemente programarlo Para el primer paso debemos especificar a wordpress que queremos crear un nuevo canal feed RSS, este canal aparecera con la siguiente [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.johandebruin.com/wp-content/uploads/2011/09/rss-icon-transparentpng.jpg" alt="RSS Widget WordPress" title="RSS Widget WordPress" width="150" height="150" class="aligncenter size-full wp-image-741" /><br />
Para crear el widget hay 2 pasos fundamentales.</p>
<ul>
<li>Crear un canal RSS con el contenido que deseas exportar
<li>Crear el widget, puedes usar uno de las muchas aplicaciones online disponibles o simplemente programarlo</li>
</ul>
<p>Para el primer paso debemos especificar a wordpress que queremos crear un nuevo canal feed RSS, este canal aparecera con la siguiente extrucutura URL:</p>
<p>http://www.ejemplo.com/?feed=ejemplo</p>
<p>http://www.ejemplo.com/feed/ejemplo/</p>
<p>Para ello creamos las siguientes funciones:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> mostrar_feed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;hola mundo&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">function</span> incluir_feed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	add_feed<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'publicadas'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mostrar_feed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'incluir_feed'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-740"></span><br />
Esto podemos incluirlo como plugin o dentro del archivo functions.php de nuestro theme.</p>
<p>Ahora dentro de la funcion mostrar_feed() indicamos el contenido RSS que queremos crear, aqui un ejemplo del codigo que he usado para <a href="http://www.partidarios.com/?feed=publicadas" title="Publicadas partidarios">http://www.partidarios.com/?feed=publicadas</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> mostrar_feed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'
	&lt;rss version=&quot;2.0&quot;
	xmlns:content=&quot;http://purl.org/rss/1.0/modules/content/&quot;
	xmlns:wfw=&quot;http://wellformedweb.org/CommentAPI/&quot;
	xmlns:dc=&quot;http://purl.org/dc/elements/1.1/&quot;
	xmlns:atom=&quot;http://www.w3.org/2005/Atom&quot;
	xmlns:sy=&quot;http://purl.org/rss/1.0/modules/syndication/&quot;
	xmlns:slash=&quot;http://purl.org/rss/1.0/modules/slash/&quot;
	&gt;
&nbsp;
&lt;channel&gt;
	&lt;title&gt;Partidarios&lt;/title&gt;
	&lt;atom:link href=&quot;http://www.partidarios.com/?feed=publicadas&quot; rel=&quot;self&quot; type=&quot;application/rss+xml&quot; /&gt;
	&lt;link&gt;http://www.partidarios.com&lt;/link&gt;
	&lt;description&gt;Feed con las ultimas publicadas de los partidos politicos.&lt;/description&gt;
	&lt;lastBuildDate&gt;Sat, 17 Sep 2011 09:45:25 +0000&lt;/lastBuildDate&gt;
&nbsp;
	&lt;language&gt;es&lt;/language&gt;
	&lt;sy:updatePeriod&gt;hourly&lt;/sy:updatePeriod&gt;
	&lt;sy:updateFrequency&gt;1&lt;/sy:updateFrequency&gt;
	&lt;generator&gt;http://wordpress.org/?v=3.2.1&lt;/generator&gt;'</span><span style="color: #339933;">;</span>
                <span style="color: #000088;">$the_query</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WP_Query<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'cat'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">27</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'meta_key'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'publicada'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'meta_value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1'</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><span style="color: #000088;">$the_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;">$the_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;">$id_partido2</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id_partido'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000088;">$id_partido</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$id_partido2</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>				
					<span style="color: #000088;">$facebook</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'facebook'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$id_partido</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$partido</span> <span style="color: #339933;">=</span> get_the_title<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id_partido</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #000088;">$mensaje</span> <span style="color: #339933;">=</span> get_the_title<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: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mensaje</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">245</span><span style="color: #009900;">&#41;</span>
					<span style="color: #009900;">&#123;</span>
						<span style="color: #000088;">$mensaje</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mensaje</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">245</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'...'</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&lt;item&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;title&gt;<span style="color: #006699; font-weight: bold;">$partido</span>: <span style="color: #006699; font-weight: bold;">$mensaje</span>&lt;/title&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;link&gt;&quot;</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span>get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/link&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;comments&gt;&quot;</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span>get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;#comments&lt;/comments&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;pubDate&gt;&quot;</span><span style="color: #339933;">.</span>get_the_date<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'D, d M Y H:i:s O'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/pubDate&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;		&lt;dc:creator&gt;admin&lt;/dc:creator&gt;<span style="color: #000099; font-weight: bold;">\n</span>
						&lt;category&gt;&lt;![CDATA[Mensaje]]&gt;&lt;/category&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;guid isPermaLink=&quot;false&quot;&gt;'</span><span style="color: #339933;">.</span>get_permalink<span style="color: #009900;">&#40;</span>get_the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/guid&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;description&gt;&lt;![CDATA[]]&gt;&lt;/description&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;content:encoded&gt;&lt;![CDATA[]]&gt;&lt;/content:encoded&gt;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
					<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;/item&gt;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
				<span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;
	&lt;/channel&gt;
&lt;/rss&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Por ultimo podemos emplear una de las muchas aplicaciones online que genera widgets a partir de archivos RSS. Una de las más sencillas es <a href="http://www.widgeteasy.com" title="Widget Facil" target="_blank">http://www.widgeteasy.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/crear-widget-exportable-a-otras-paginas-web-con-el-contenido-de-tu-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Huevo de pascua autodestrucción de wordpress y Matrix</title>
		<link>http://www.johandebruin.com/huevo-de-pascua-autodestruccion-de-wordpress-y-matrix/</link>
		<comments>http://www.johandebruin.com/huevo-de-pascua-autodestruccion-de-wordpress-y-matrix/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 15:35:27 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[Humor]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=622</guid>
		<description><![CDATA[Este es un curioso huevo de pascua de wordpress, se activa cuando tratas de comparar 2 versiones de una entrada y selecciones revisar la misma versión. Para ello podemos usar un enlace generico como este cambiando la id por una id de algun post que queramos revisar: http://www.url.com/wp-admin/revision.php?revision=id&#038;action=edit Cuando intentas comparar la misma versión salta [...]]]></description>
			<content:encoded><![CDATA[<p>Este es un curioso huevo de pascua de wordpress, se activa cuando tratas de comparar 2 versiones de una entrada y selecciones revisar la misma versión. Para ello podemos usar un enlace generico como este cambiando la id por una id de algun post que queramos revisar:</p>
<p>http://www.url.com/wp-admin/revision.php?revision=id&#038;action=edit</p>
<p>Cuando intentas comparar la misma versión salta una serie de mensajes, los primeros avisando de la autodestrucción de tu blog y luego simulando la conversación de neo y triniti frente al ordenador al principio de la peliculas <a href="http://es.wikipedia.org/wiki/The_Matrix">The Matrix </a>.</p>
<p>Aqui unas capturas del evento:</p>
<p><a href="http://www.johandebruin.com/wp-content/uploads/2010/09/huevo-pascua-wordpress-matrix-1.jpg"><img class="aligncenter size-full wp-image-624" title="huevo pascua wordpress matrix 1" src="http://www.johandebruin.com/wp-content/uploads/2010/09/huevo-pascua-wordpress-matrix-1.jpg" alt="" width="776" height="194" /></a></p>
<p><a href="http://www.johandebruin.com/wp-content/uploads/2010/09/huevo-pascua-wordpress-matrix-2.jpg"><img src="http://www.johandebruin.com/wp-content/uploads/2010/09/huevo-pascua-wordpress-matrix-2.jpg" alt="" title="huevo pascua wordpress matrix 2" width="776" height="114" class="aligncenter size-full wp-image-625" /></a></p>
<p><a href="http://www.johandebruin.com/wp-content/uploads/2010/09/huevo-pascua-wordpress-matrix-3.jpg"><img src="http://www.johandebruin.com/wp-content/uploads/2010/09/huevo-pascua-wordpress-matrix-3.jpg" alt="" title="huevo pascua wordpress matrix 3" width="777" height="111" class="aligncenter size-full wp-image-626" /></a></p>
<p><a href="http://www.johandebruin.com/wp-content/uploads/2010/09/huevo-pascua-wordpress-matrix-4.jpg"><img src="http://www.johandebruin.com/wp-content/uploads/2010/09/huevo-pascua-wordpress-matrix-4.jpg" alt="" title="huevo pascua wordpress matrix 4" width="776" height="117" class="aligncenter size-full wp-image-627" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/huevo-de-pascua-autodestruccion-de-wordpress-y-matrix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>2 dominios, 2 idiomas, htaccess, wordpress, alias y 1 servidor</title>
		<link>http://www.johandebruin.com/2-dominios-2-idiomas-htaccess-wordpress-alias-y-1-servidor/</link>
		<comments>http://www.johandebruin.com/2-dominios-2-idiomas-htaccess-wordpress-alias-y-1-servidor/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 11:15:44 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=615</guid>
		<description><![CDATA[Hoy voy a hablaros de una de las tecnicas mas enrevesadas para conseguir que tengamos 2 idiomas en un mismo servidor pero usando 2 dominios distintos (y asi reforzar el posicionamiento seo por dominios del pais). La forma en la que os lo muestro es usando wordpress, pero por supuesto se podria adaptar para otros [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy voy a hablaros de una de las tecnicas mas enrevesadas para conseguir que tengamos 2 idiomas en un mismo servidor pero usando 2 dominios distintos (y asi reforzar el posicionamiento seo por dominios del pais).</p>
<p>La forma en la que os lo muestro es usando wordpress, pero por supuesto se podria adaptar para otros cms o vuestros propios sistemas. Primero deciros que usaremos el plugin de traducción de idiomas estilo <a href="http://wordpress.org/extend/plugins/zdmultilang/">zdMultilang</a> que nos permitira crear subdirectorios estilo dominioprincipal.es/en/ para las traducciones.</p>
<p>Una vez hecho esto, debeis añadir un <a href="http://www.seocharlie.com/blog/los-alias-de-dominio-y-el-posicionamiento-seo">alias </a>al dominio principal para que al entrar desde el segundo dominio conecte con las dns del servidor principal.</p>
<p>Ahora comenzamos a tocar las lineas de codigo, primero abriremos el htaccess y añadiremos las siguientes instrucciones para que el dominio secundario haga un proxy al dominio principal y obtenga la url actual pero añadiendo /en/ al host. En este ejemplo el dominio principal es un .es y el dominio secundario (en ingles o internacional) es el .com:</p>

<div class="wp_syntax"><div class="code"><pre class="robots" style="font-family:monospace;">RewriteEngine on
RewriteCond %<span style="color: #66cc66;">&#123;</span>HTTP_HOST<span style="color: #66cc66;">&#125;</span> ^<span style="color: #66cc66;">&#40;</span>www\.<span style="color: #66cc66;">&#41;</span>?dominiosecundario\.com <span style="color: #66cc66;">&#91;</span>NC<span style="color: #66cc66;">&#93;</span>
RewriteRule ^<span style="color: #66cc66;">&#40;</span>.*<span style="color: #66cc66;">&#41;</span>$ http<span style="color: #66cc66;">:</span>//www.dominioprincipal.es/en/$1 <span style="color: #66cc66;">&#91;</span>P<span style="color: #66cc66;">&#93;</span>
&nbsp;
RewriteRule ^/?<span style="color: #66cc66;">&#40;</span>en<span style="color: #66cc66;">&#41;</span>/wp-<span style="color: #66cc66;">&#40;</span>.*<span style="color: #66cc66;">&#41;</span>$ /wp-$2 <span style="color: #66cc66;">&#91;</span>L<span style="color: #66cc66;">&#93;</span></pre></div></div>

<p><span id="more-615"></span><br />
Además, añadirmos la instrucción RewriteRule ^/?(en)/wp-(.*)$ /wp-$2 [L] para que todos las peticiones que comiencen con wp- ignoren el /en/. Esto se hace para que en la versión inglesa pueda obtener el contenido de imagenes, o scripts de forma correcta..</p>
<p>Ahora incluiremos algunas líneas de código de wordpress, que haran que detecten si se está en el dominio secundario y cambie las url de las imagenes y los scripts a este dominio con tal de evitar incompatibilidades de rutas, etc.. Estas lineas se pueden incluir en el archivo functions.php del theme o en forma de plugin, esto se pone a vuestra discreción&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bloginfo'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mybloginfo'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'bloginfo_url'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'mybloginfo'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> mybloginfo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$result</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$show</span><span style="color: #339933;">=</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strpos</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'/en/'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #990000;">ereg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dominioprincipal.es'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'dominiosecundario.com'</span><span style="color: #339933;">,</span><span style="color: #000088;">$result</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Bien, ya tenemos hecho la base necesaria para poder incluir un segundo idioma en el servidor con 2 dominios distintos, podemos usar la instrucción if (strpos($_SERVER['REQUEST_URI'],&#8217;/en/&#8217;) > -1) para detectar si estamos en la versión inglesa de la traducción y cambiar valores del contenido, como menus, o rutas&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/2-dominios-2-idiomas-htaccess-wordpress-alias-y-1-servidor/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Configurar el loop de wordpress</title>
		<link>http://www.johandebruin.com/configurar-el-loop-de-wordpress/</link>
		<comments>http://www.johandebruin.com/configurar-el-loop-de-wordpress/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 11:26:26 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[API wordpress]]></category>
		<category><![CDATA[Custom loop]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=609</guid>
		<description><![CDATA[Hoy os traigo otro artículo para incorporarlo en la api de wordpress, el loop de wordpress es invocado cada vez que solicitamos articulos o páginas, en el index por ejemplo sale por defecto la solicitud de los últimos artículos publicados, en el archivo los articulos de cierto mes o cierta categoria, etc&#8230; La api de [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy os traigo otro artículo para incorporarlo en la <a href="http://www.johandebruin.com/tutorial-api-wordpress/">api de wordpress</a>, el <strong>loop de wordpress </strong>es invocado cada vez que solicitamos articulos o páginas, en el index por ejemplo sale por defecto la solicitud de los últimos artículos publicados, en el archivo los articulos de cierto mes o cierta categoria, etc&#8230;</p>
<p>La <strong>api de wordpress nos permite una configuración bastante intensa </strong>de la forma de solicitar y mostrar contenido en los loops de wordpress, lo primero de todo es establecer los posts que queramos mostrar en el loop, se puede hacer usando la función <a href="http://codex.wordpress.org/Function_Reference/query_posts">query_posts()</a>;</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cat=4,5'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Todos los que esten en la categoria 4 y 5</span>
query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'tag=mitag'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Los que tengan cierto tag...</span>
query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'meta_key=nombrekey&amp;amp;meta_value=valorkey'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Tenga un campo personalizado con dichos valores</span>
&nbsp;
 <span style="color: #000088;">$categoria</span><span style="color: #339933;">=</span><span style="color: #000088;">$cat</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// asignamos la actual categoria</span>
 <span style="color: #000088;">$query</span><span style="color: #339933;">=</span> <span style="color: #0000ff;">'cat='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$categoria</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;amp;orderby=date&amp;amp;order=ASC'</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//ordenacion ascendente por fecha</span>
 query_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><span id="more-609"></span><br />
Como veis, tenemos mucho con que jugar a la hora de configurar el contenido del loop de wordpress, una vez hecho podemos crear el loop, tiene la siguiente estructura:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><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: #666666; font-style: italic;">//...</span>
<span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span><span style="color: #339933;">:</span>
<span style="color: #666666; font-style: italic;">//...</span>
<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span>
wp_reset_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Importante reiniciar loop para que wordpress funcione como habitualmente</span></pre></div></div>

<p>Una vez dentro del loop podemos llamar a muchos valores de los posts, como por ejemplo el contenido, los tags, fecha, titulos, extracto, campos personalizados, la categoria&#8230; Aquí un ejemplo de como seria el código completo</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">query_posts('cat='.get_cat_ID('miCategoria')); //Establecemos el query con los posts de &quot;miCategoria&quot;
if (have_posts()) : while (have_posts()) : the_post();
     &lt;p&gt;&lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;&lt;/p&gt;
     &lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_excerpt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> ?<span style="color: #339933;">&lt;/</span>p<span style="color: #339933;">&gt;</span>
     <span style="color: #339933;">&lt;</span>p<span style="color: #339933;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;?</span>php the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$postMeta</span> <span style="color: #339933;">=</span> get_post_custom_values<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'metaKey'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$postMeta</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;p&gt;<span style="color: #006699; font-weight: bold;">$key</span>  =&gt; <span style="color: #006699; font-weight: bold;">$value</span> ('metaKey')&lt;/p&gt;&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
endwhile; else:
    echo &quot;No se encontraron articulos relacionados, puede que le interese alguna de las siguientes categorias&quot;
&lt;ul&gt;
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_list_categories<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ul&gt;
endif;
wp_reset_query();</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/configurar-el-loop-de-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Crear Plantillas de themes para post en WordPress</title>
		<link>http://www.johandebruin.com/crear-plantillas-de-themes-para-post-en-wordpress/</link>
		<comments>http://www.johandebruin.com/crear-plantillas-de-themes-para-post-en-wordpress/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 20:42:28 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Custom Values]]></category>
		<category><![CDATA[Plantilla]]></category>
		<category><![CDATA[Post meta]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[Wordpress API]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=599</guid>
		<description><![CDATA[Podemos crear una plantilla para publicar post especificos en wordpress de la misfa forma que ocurre con las páginas gracias a la combinación del uso de la API de wordpress y del plugin Custom Post Template. Lo que queremos conseguir es mostrar posts de distintas maneras en función a que plantilla seleccionamos en el menu [...]]]></description>
			<content:encoded><![CDATA[<p>Podemos crear una plantilla para publicar post especificos en wordpress de la misfa forma que ocurre con las páginas gracias a la combinación del uso de la API de wordpress y del plugin <a title="Plantilla Post WordPress" href="http://wordpress.org/extend/plugins/custom-post-template/">Custom Post Template</a>. Lo que queremos conseguir es mostrar posts de distintas maneras en función a que plantilla seleccionamos en el menu de post:</p>
<p><a href="http://www.johandebruin.com/wp-content/uploads/2010/06/post-template.jpg"><img src="http://www.johandebruin.com/wp-content/uploads/2010/06/post-template.jpg" alt="" title="post template" width="296" height="365" class="aligncenter size-full wp-image-600" /></a></p>
<p>Gracias a eso, y a un formato de recognición de templates de post, con que añadamos el siguiente comentario en el .php del theme de wordpress podremos definir un formato especifico para ese tipo de post (como añadir metas especificos, imagenes, colores, opciones etc&#8230; especifico), explotando más las posibilidades de wordpress.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Template Name Posts: nombrePlantilla
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p><span id="more-599"></span><br />
Aqui un ejemplo de como podriamos adaptar esta plantilla usando comandos de la API de wordpress (lo tipico, llamada al header, titulos, contenido, campos personalizados.. ).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Template Name Posts: nombrePlantilla
*/</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_header<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
   &lt;h1&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
   <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&lt;p class=&quot;serif&quot;&gt;Leer el resto del post;&lt;/p&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   $postMeta = get_post_custom_values('metaKey');
   foreach ( $postMeta as $key =&gt; $value ) {
      echo &quot;$key  =&gt; $value ('metaKey')&lt;br /&gt;&quot;; 
   }
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/crear-plantillas-de-themes-para-post-en-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Añadir opciones a un plugin wordpress</title>
		<link>http://www.johandebruin.com/anadir-opciones-a-un-plugin-wordpress/</link>
		<comments>http://www.johandebruin.com/anadir-opciones-a-un-plugin-wordpress/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 14:18:29 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Añadir opciones wordpress]]></category>
		<category><![CDATA[API wordpress]]></category>
		<category><![CDATA[Opciones wordpress]]></category>
		<category><![CDATA[Plugin wordpress]]></category>
		<category><![CDATA[Programar plugins wordpress]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=480</guid>
		<description><![CDATA[Consta de una variable para establecer un nombre de id para establecer las opciones en la base de datos, añadir la acción al hook del menu al construir el plugin, establecer como aparecerá en la pestaña las opcinones con add_options_page, y el código que mostrará y gestionará las opciones insertadas. Aquí un ejemplo básico de [...]]]></description>
			<content:encoded><![CDATA[<p>Consta de una variable para establecer un nombre de id para establecer las opciones en la base de datos, añadir la acción al hook del menu al construir el plugin, establecer como aparecerá en la pestaña las opcinones con <strong>add_options_page</strong>, y el código que mostrará y gestionará las opciones insertadas. Aquí un ejemplo básico de como quedaría:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">class</span> miPlugin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$db_option</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'miPlugin_Options'</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> miPlugin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">//Línea para incluir el menú</span>
		add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'miMenu'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'admin_menu'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> miMenu<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		add_options_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Opciones del plugin'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Algun id'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #990000;">basename</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'opciones'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">function</span> opciones<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_options</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'submitted'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		  check_admin_referer<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nonce'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		  <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		  <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		  <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		  update_option<span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">db_option</span><span style="color: #339933;">,</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// Aquí establecemos algunas variables que usaremos en el form</span>
		<span style="color: #000088;">$action_url</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$a</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'a'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$b</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'b'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
       	&lt;form name=&quot;SnazzyArchives&quot; action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$action_url</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; method=&quot;post&quot;&gt;
            <span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_nonce_field<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nonce'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
            &lt;input type=&quot;checkbox&quot; name=&quot;a&quot;  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$a</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> /&gt;&lt;label&gt; Show Posts&lt;/label&gt;  &lt;br /&gt;
            &lt;input type=&quot;checkbox&quot; name=&quot;b&quot;  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$b</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> /&gt;&lt;label&gt; Show Pages&lt;/label&gt;  &lt;br /&gt;
            &lt;div&gt;&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;Update&quot; /&gt;&lt;/div&gt;
       	&lt;/form&gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Solo decir que que las opciones se obtienen con <em>$options = $this->get_options();</em> y se establecen con <em>update_option($this->db_option, $options);</em> Además, <em><?php wp_nonce_field('nonce'); ?></em> sirve como parametro de seguridad para cercionarnos que se está empleando el formulario correcto. Esto luego se comprueba con <em>check_admin_referer(&#8216;nonce&#8217;);</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/anadir-opciones-a-un-plugin-wordpress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Estructura de la clase php de un plugin de wordpress</title>
		<link>http://www.johandebruin.com/estructura-de-la-clase-php-de-un-plugin-de-wordpress/</link>
		<comments>http://www.johandebruin.com/estructura-de-la-clase-php-de-un-plugin-de-wordpress/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 15:31:58 +0000</pubDate>
		<dc:creator>Johan</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[clase php]]></category>
		<category><![CDATA[Clase plugin]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[Plugin wordpress]]></category>
		<category><![CDATA[Programacion wordpress]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=450</guid>
		<description><![CDATA[Los buenos plugins de wordpress están desarrollados a través de una clase php con la que se optimiza el código. Aquí traigo un ejemplo de la estructura básica de la programación php para declarar la clase e insertar el constructor y un método que se autoejecutará al iniciar la clase que instalará el plugin. &#60;?php [...]]]></description>
			<content:encoded><![CDATA[<p>Los buenos plugins de wordpress están desarrollados a través de una clase php con la que se optimiza el código. Aquí traigo un ejemplo de la estructura básica de la programación php para <strong>declarar la clase </strong>e insertar el constructor y un <strong>método </strong>que se autoejecutará al iniciar la clase <strong>que instalará el plugin</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/*
Plugin name: Nombre de mi plugin
Version: 0.1
Plugin URI: http://www.johandebuin.com/miplugin
Author: Johan de Bruin
Author URI: http://www.johandebruin.com
Description: una descripción sobre que hace el plugin en cuestión
*/</span></pre></div></div>

<p><span id="more-450"></span><br />
Ahora declaramos un if para comprobar si la clase ya existe, en caso contrario la definimos.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'clasePlugin'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span>
<span style="color: #000000; font-weight: bold;">class</span> clasePlugin
<span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">//Esta variable sirve para obtener la url del plugin</span>
     <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$plugin_url</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #666666; font-style: italic;">//Constructor del plugin</span>
     <span style="color: #000000; font-weight: bold;">function</span> clasePlugin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">plugin_url</span> <span style="color: #339933;">=</span> trailingslashit<span style="color: #009900;">&#40;</span> WP_PLUGIN_URL<span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span> <span style="color: #990000;">dirname</span><span style="color: #009900;">&#40;</span> plugin_basename<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #666666; font-style: italic;">//Línea para incluir los scripts a la pagina</span>
          add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_print_scripts'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'misScripts'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #000000; font-weight: bold;">function</span> instalar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">//Sentencias como la creación de una BD</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
     <span style="color: #000000; font-weight: bold;">function</span> misScripts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
     <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">//Añadimos un script en jquery</span>
          wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'clasePlugin'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">plugin_url</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/rutaDeljquery.js'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #666666; font-style: italic;">//Añadimos un css</span>
          <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;link rel=&quot;stylesheet&quot; href=&quot;'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">plugin_url</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/estilo.css&quot; type=&quot;text/css&quot; /&gt;'</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span>
     <span style="color: #990000;">exit</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;La clase clasePlugin ya esta declarada&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span></pre></div></div>

<p>Por último creamos la instancia de la clase, emplearemos la función de wordpress <strong>register_activation_hook</strong> cuyos parametros son fichero del <em>plugin </em>y <em>callback</em>, para especificar que queremos que se ejecute la función <strong>instalar </strong>al activar el plugin.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$instanciaPlugin</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> clasePlugin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$instanciaPlugin</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">//Recuerda que la &amp; sirve para que los cambios realizados en la variable en la función</span>
     <span style="color: #666666; font-style: italic;">//surtan efecto a nivel global y no solo dentro de la variable.</span>
     register_activation_hook<span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">__FILE__</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #000088;">$instanciaPlugin</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'instalar'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Y recuerda, el codigo es poesia <img src='http://www.johandebruin.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/estructura-de-la-clase-php-de-un-plugin-de-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Crear y configurar un widget de wordpress</title>
		<link>http://www.johandebruin.com/crear-y-configurar-un-widget-de-wordpress/</link>
		<comments>http://www.johandebruin.com/crear-y-configurar-un-widget-de-wordpress/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 16:17:42 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[Crear widget wordpress]]></category>
		<category><![CDATA[header hook wordpress]]></category>
		<category><![CDATA[Plugin wordpress]]></category>
		<category><![CDATA[Programacion]]></category>
		<category><![CDATA[Widget]]></category>
		<category><![CDATA[Wordpress API]]></category>
		<category><![CDATA[Wordpress hook]]></category>
		<category><![CDATA[Wordpress widget]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=349</guid>
		<description><![CDATA[Para crear un widget con wordpress solo debemos definirlo en el archivo donde alojemos el plugin de wordpress, no obstante, un widget permite ajustar una serie de opciones, en el siguiente codigo de programación aprenderemos a aprovechar el potencia de widgets de wordpress para que podamos añadir facilmente aplicaciones en los sidebar de tu blog. [...]]]></description>
			<content:encoded><![CDATA[<p>Para <strong>crear un widget con wordpress </strong>solo debemos definirlo en el archivo donde alojemos el plugin de wordpress, no obstante, un widget permite ajustar una serie de opciones, en el siguiente codigo de programación aprenderemos a aprovechar el potencia de <strong>widgets de wordpress </strong>para que podamos añadir facilmente aplicaciones en los <strong>sidebar de tu blog</strong>.<br />
<span id="more-349"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">function</span> miplugin_Widget<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$user_ID</span><span style="color: #339933;">,</span> <span style="color: #000088;">$user_identity</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_wall_plugin_url</span><span style="color: #339933;">;</span>
      <span style="color: #666666; font-style: italic;">// extract the parameters</span>
      <span style="color: #990000;">extract</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// get our options</span>
      <span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'miplugin'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000088;">$titulo</span><span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'miplugin_titulo'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// Estas variables son por cuestión de compatibilidad del theme</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_widget</span><span style="color: #339933;">;</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$before_title</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$titulo</span><span style="color: #339933;">.</span> <span style="color: #000088;">$after_title</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">// El texto y código que inluirá nuestro widget</span>
      <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;HOLA MUNDO!&quot;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$after_widget</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Desarrollamos lo que debe hacer el plugin al activarse</span>
<span style="color: #000000; font-weight: bold;">function</span> miplugin_init<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     register_sidebar_widget<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Nombre plugin'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'miplugin_Widget'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     register_widget_control<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Nombre plugin'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'miplugin_WidgetControl'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">//Acción que indica la función de activación del plugin</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'miplugin_init'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Con estas lineas de código podemos cambiar las opciones del plugin con tal de que podamos establecer el título del widget que aparecerá en el sidebar.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">function miplugin_WidgetControl()
{
      // Obtenemos los valores preestablecidos
      $options = get_option('miplugin');
      // Cambiamos las opciones en caso de que haya un post
      if ($_POST[&quot;miplugin_submit&quot;]) {
          // retireve wall title from the request
          $options['miplugin_titulo'] = strip_tags(stripslashes($_POST[&quot;miplugin_titulo&quot;]));
          // update the options to database
          update_option('miplugin', $options);
      }
      $titulo = $options['titulo'];
      // Lo que se imprime en las opciones del widget
      ?&gt;
&lt;p&gt;
Titulo: &lt;input  name=&quot;miplugin_titulo&quot; type=&quot;text&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$titulo</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
&lt;input type=&quot;hidden&quot; id=&quot;miplugin_submit&quot; name=&quot;miplugin_submit&quot; value=&quot;1&quot; /&gt;
&lt;/p&gt;
     <span style="color: #000000; font-weight: bold;">&lt;?</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/crear-y-configurar-un-widget-de-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Añadir codigos al header en wordpress</title>
		<link>http://www.johandebruin.com/anadir-codigos-al-header-en-wordpress/</link>
		<comments>http://www.johandebruin.com/anadir-codigos-al-header-en-wordpress/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 19:20:57 +0000</pubDate>
		<dc:creator>Johan de Bruin</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[API wordpress]]></category>
		<category><![CDATA[codigo css plugin]]></category>
		<category><![CDATA[header hook wordpress]]></category>

		<guid isPermaLink="false">http://www.johandebruin.com/?p=291</guid>
		<description><![CDATA[A menudo querremos integrar dentro de la estructura distintos códigos para poder añadir comportamientos a la página web, (como algo de CSS o Javascript). Si no queremos andar añadiendo código al header.php del theme, podemos añadirselo gracias a un fabuloso hook que integra la API de WordPress. function estilo_css&#40;&#41; &#123; body &#123; background-color:#ffffff !important; } [...]]]></description>
			<content:encoded><![CDATA[<p>A menudo querremos integrar dentro de la estructura <head> distintos códigos para poder añadir comportamientos a la página web, (como algo de CSS o Javascript). Si no queremos andar añadiendo código al header.php del theme, podemos añadirselo gracias a un fabuloso <strong>hook</strong> que integra la <strong>API de WordPress</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> estilo_css<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     body <span style="color: #009900;">&#123;</span> background<span style="color: #339933;">-</span>color<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">#ffffff !important; }
</span><span style="color: #009900;">&#125;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'admin_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'estilo_css'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.johandebruin.com/anadir-codigos-al-header-en-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

