<?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>emenia.es &#187; Wordpress</title>
	<atom:link href="http://www.emenia.es/category/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.emenia.es</link>
	<description>Creación y diseño web</description>
	<lastBuildDate>Mon, 31 May 2010 14:34:56 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Crear una lista de productos con Wordpress 3.0 usando Entradas personalizadas, campos personalizados y taxonomías</title>
		<link>http://www.emenia.es/lista-productos-wordpress-3/</link>
		<comments>http://www.emenia.es/lista-productos-wordpress-3/#comments</comments>
		<pubDate>Sun, 30 May 2010 16:34:01 +0000</pubDate>
		<dc:creator>Juan Diaz-Bustamante</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.emenia.es/?p=875</guid>
		<description><![CDATA[Una de las grandes novedades que incorpora Wordpress 3.0 es la posibilidad de crear <strong>Entradas Personalizadas (Custom Post Types)</strong>, es decir un nuevo tipo de entradas parecidas a las Entradas normales y a las Páginas, y que <strong>aparecerán también de manera separada en el menú de la izquierda del administrador de Wordpress</strong>. ¿Qué ventajas nos ofrecen las Entradas Personalizadas? Una mayor facilidad de uso de nuestro tema, estructurando mejor los distintos tipos de entradas.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.emenia.es%2Flista-productos-wordpress-3%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.emenia.es%2Flista-productos-wordpress-3%2F&amp;source=JuanDBB_Emenia&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Una de las grandes novedades que incorpora Wordpress 3.0 es la posibilidad de crear <strong>Entradas Personalizadas (Custom Post Types)</strong>, es decir un nuevo tipo de entradas parecidas a las Entradas normales y a las Páginas, y que <strong>aparecerán también de manera separada en el menú de la izquierda del administrador de Wordpress</strong>. ¿Qué ventajas nos ofrecen las Entradas Personalizadas? Una mayor facilidad de uso de nuestro tema, estructurando mejor los distintos tipos de entradas. Por ejemplo, si queremos insertar una lista de productos con una serie de características comunes, podemos crear una estradas personalizadas que se llamen <strong>Producto</strong> y que estén configuradas de manera específica para insertar dichos productos. En vez de decirle a nuestro cliente que cree una entrada normal y que rellene toda una serie de campos personalizados sólo utilizables para insertar un producto pero no para cualquier otra entrada, que no se equivoque con las categorías que son sólo para productos y no para el resto de entradas, etc.. ahora símplemente tendrá que hacer click en &#8220;Productos&#8221; y rellenar cada campo específico para ese tipo de entrada.</p>
<p><a href="http://www.emenia.es/wp-content/uploads/2010/05/menu_admin.png"><img src="http://www.emenia.es/wp-content/uploads/2010/05/menu_admin.png" alt="" title="menu_admin" width="500" height="293" class="aligncenter size-full wp-image-880" /></a></p>
<p>Pero como siempre, esto se verá mejor con un ejemplo. Vamos a crear una entrada personalizada que se llame &#8220;Productos&#8221;. Con el permiso de <a href="http://www.friendware.es" title="Ir a Friendware">Friendware</a> (su web la hice yo hace un par de años) vamos a usar algunos de sus juegos para PC. Cada producto va a tener un título, una descripción, un precio, un fabricante, una plataforma y una imagen.</p>
<p>Vamos a usar campos personalizados para el precio y el fabricante y taxonomías personalizadas para la Plataforma (en realidad Fabricante debería ser una taxonomía, pero lo pongo como campo personalizado para ver mejor cómo se crean varios).</p>
<p><strong>En el administrador vamos a tener en el menú de la izquierda:</strong></p>
<p><a href="http://www.emenia.es/wp-content/uploads/2010/05/menu_admin2.png"><img src="http://www.emenia.es/wp-content/uploads/2010/05/menu_admin2.png" alt="" title="menu_admin2" width="500" height="302" class="aligncenter size-full wp-image-887" /></a></p>
<p><strong>Si hacemos click sobre Añadir tendremos:</strong></p>
<p><a href="http://www.emenia.es/wp-content/uploads/2010/05/anadir_producto.png"><img src="http://www.emenia.es/wp-content/uploads/2010/05/anadir_producto.png" alt="" title="anadir_producto" width="500" height="418" class="aligncenter size-full wp-image-890" /></a></p>
<p><strong>Y al hacer click sobre Editar tendremos una tabla con todos los productos:</strong></p>
<p><a href="http://www.emenia.es/wp-content/uploads/2010/05/editar_producto.png"><img src="http://www.emenia.es/wp-content/uploads/2010/05/editar_producto.png" alt="" title="editar_producto" width="550" height="361" class="aligncenter size-full wp-image-893" /></a><br />
<strong><br />
Pero ahora viene lo mejor.</strong> Si tenemos activados los enlaces permanentes podemos ir a una url que sea por ejemplo www.miweb.es/Productos/ donde se vean todos los productos introducidos con los estilos que hayamos definido:</p>
<p><a href="http://www.emenia.es/wp-content/uploads/2010/05/productos1.jpg"><img src="http://www.emenia.es/wp-content/uploads/2010/05/productos1.jpg" alt="" title="productos" width="500" height="570" class="aligncenter size-full wp-image-926" /></a><br />
<strong><br />
Bien, ya sabemos lo que vamos a crear. Ahora vamos a ver paso a paso cómo crearlo.</strong> No he visto ningún artículo completo que indique todos lo pasos de manera completa. Por ello me he basado en diferentes artículos y webs. Sus enlaces están al final del artículo.</p>
<h3>Paso 1: Crear una Entrada Personalizada</h3>
<p>La mejor manera que he encontrado para crear una Entrada Personalizada es utilizando la <a href="http://somadesign.ca/projects/smarter-custom-post-types/" title="Ir al blog de Matt Wiebe">clase creada por Matt Wiebe</a>. La razón es que además de crear una función que nos permite crear Entradas Personalizadas con gran facilidad, añade a la función que habitualmente crea entradas personalizadas (<a href="http://codex.wordpress.org/Function_Reference/register_post_type">register_post_type</a>) una serie de funcionalidades extra:</p>
<p>   1. URLs personalizadas para cada Entrada Personalizada. (ejemplos http://miweb.com/productos/, http://miweb.com/productos/page/2/, http://miweb.com/productos/feed/ )<br />
   2. Archivos personalizados para cada Entrada Personalizada, por ejemplo producto/index.php o producto.php en el directorio de nuestro tema.<br />
   3. Páginas individuales personalizadas: WP busca el fichero single-producto.php (en su defecto por single.php). Con esta función podemos usar producto/single.php para una mejor organización..<br />
   4. Añade clases a body_class() y a post_class().<br />
   5. Auto genera las etiquetas apropiadas para el Administrador si no suministras una.</p>
<p>El punto 1 me parece muy importante, ya que Wordpress 3.0, al menos en la beta 2, no crea por defecto una url donde podamos ver todas las entradas de una misma entrada personalizada (por ejemplo, todos los productos).</p>
<p>El código, que habría que llevar al archivo functions.php, lo podemos descargar <a href="http://somadesign.ca/projects/smarter-custom-post-types/">desde la web de Matt Wiebe</a>. Una vez tengamos ese código pegado en el archivo functions.php de nuestro tema, escribiremos a continuación para crear la Entrada Personalizada &#8220;Producto&#8221;:</p>

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

<p>Aquí está el código completo. Hay que tener en cuenta que Matt Wiebe está continuamente mejorando esta función añadiendo nuevas características, por lo que estad pendientes de sus actualizaciones.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
 * Copyright 2010 Matt Wiebe.
 *
 * This code is licensed under the GPL v2.0
 * http://www.opensource.org/licenses/gpl-2.0.php
 *
 * If you do something cool with it, let me know! http://somadesign.ca/contact/
 *
 * Version 1.3
 *
 * === Changelog ===
 *
 * 1.0
 *  - Initial release
 * 1.1
 *  - Added feed support in URL rewrites
 * 1.2
 *  - Removed redundant post_class code.
 *  - Removed redundant single post_type template code
 *  - Introduced directory support for template files
 * 1.3
 *  - Use the newer, more robust labels array to set defaults
 *  - Add possible support for adding post_type to nav_menus. Commented out by default since the 'show_in_nav_menus' $arg should provide for that, although it doesn't seem to work right now.
 *
 */</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * SD_Register_Post_Type class
 *
 * @author Matt Wiebe
 * @link http://somadesign.ca
 *
 * @param string $post_type The post type to register
 * @param array $args The arguments to pass into @link register_post_type(). Some defaults provided to ensure the UI is available.
 * @param string $custom_plural The plural name to be used in rewriting (http://yourdomain.com/custom_plural/ ). If left off, an &quot;s&quot; will be appended to your post type, which will break some words. (person, box, ox. Oh, English.)
 **/</span>
&nbsp;
<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;">'SD_Register_Post_Type'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">class</span> SD_Register_Post_Type <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$post_type</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$post_slug</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$args</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$post_type_object</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$defaults</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'show_ui'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'public'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'supports'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'editor'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'thumbnail'</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> set_defaults<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$plural</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ucwords</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_slug</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$post_type</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ucwords</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">defaults</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'labels'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
				<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$plural</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'singular_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$post_type</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'add_new_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Add New '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$post_type</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'edit_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Edit '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$post_type</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'new_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'New '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$post_type</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'view_item'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'View '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$post_type</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'search_items'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Search '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$plural</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'not_found'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'No '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$plural</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' found'</span><span style="color: #339933;">,</span>
				<span style="color: #0000ff;">'not_found_in_trash'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'No '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$plural</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' found in Trash'</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;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post_type</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</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: #339933;">,</span> <span style="color: #000088;">$custom_plural</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</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: #339933;">!</span> <span style="color: #000088;">$post_type</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// meat n potatoes</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$post_type</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_slug</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$custom_plural</span> <span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$custom_plural</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$post_type</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'s'</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// a few extra defaults. Mostly for labels. Overridden if proper $args present.</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_defaults</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #666666; font-style: italic;">// sort out those $args</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">args</span> <span style="color: #339933;">=</span> wp_parse_args<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">defaults</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #666666; font-style: italic;">// magic man</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_actions</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">add_filters</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> add_actions<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'init'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'register_post_type'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'template_redirect'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'context_fixer'</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;">public</span> <span style="color: #000000; font-weight: bold;">function</span> add_filters<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'generate_rewrite_rules'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'add_rewrite_rules'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'template_include'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'template_include'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			add_filter<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'body_class'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'body_classes'</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;">public</span> <span style="color: #000000; font-weight: bold;">function</span> context_fixer<span style="color: #009900;">&#40;</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> get_query_var<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'post_type'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</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;">$wp_query</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$wp_query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">is_home</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> add_rewrite_rules<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wp_rewrite</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$new_rules</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;">$new_rules</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_slug</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/page/?([0-9]{1,})/?$'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'index.php?post_type='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;paged='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">preg_index</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$new_rules</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_slug</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/(feed|rdf|rss|rss2|atom)/?$'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'index.php?post_type='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&amp;feed='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">preg_index</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$new_rules</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_slug</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/?$'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'index.php?post_type='</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rules</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_merge</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$new_rules</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">rules</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$wp_rewrite</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> register_post_type<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			register_post_type<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">args</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;">public</span> <span style="color: #000000; font-weight: bold;">function</span> template_include<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$template</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> get_query_var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_type'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> is_single<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: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$single</span> <span style="color: #339933;">=</span> locate_template<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/single.php'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
						<span style="color: #b1b100;">return</span> <span style="color: #000088;">$single</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #666666; font-style: italic;">// loop</span>
					<span style="color: #b1b100;">return</span> locate_template<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
						<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/index.php'</span><span style="color: #339933;">,</span>
						<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'.php'</span><span style="color: #339933;">,</span>
						<span style="color: #0000ff;">'index.php'</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: #009900;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$template</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> body_classes<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$c</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> get_query_var<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post_type'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$c</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'type-'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_type</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #009900;">&#125;</span> <span style="color: #666666; font-style: italic;">// end SD_Register_Post_Type class</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * A helper function for the SD_Register_Post_Type class. Because typing &quot;new&quot; is hard.
	 *
	 * @author Matt Wiebe
	 * @link http://somadesign.ca
	 *
	 * @uses SD_Register_Post_Type class
	 * @param string $post_type The post type to register
	 * @param array $args The arguments to pass into @link register_post_type(). Some defaults provided to ensure the UI is available.
	 * @param string $custom_plural The plural name to be used in rewriting (http://yourdomain.com/custom_plural/ ). If left off, an &quot;s&quot; will be appended to your post type, which will break some words. (person, box, ox. Oh, English.)
	 **/</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'sd_register_post_type'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #990000;">class_exists</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'SD_Register_Post_Type'</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;">function</span> sd_register_post_type<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post_type</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</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: #339933;">,</span> <span style="color: #000088;">$custom_plural</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$custom_post</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SD_Register_Post_Type<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$post_type</span><span style="color: #339933;">,</span> <span style="color: #000088;">$args</span><span style="color: #339933;">,</span> <span style="color: #000088;">$custom_plural</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;">&#125;</span>
&nbsp;
sd_register_post_type<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'Producto'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Del código de Matt Wiebe hay que destacar esta parte:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$defaults</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
	<span style="color: #0000ff;">'show_ui'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'public'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
	<span style="color: #0000ff;">'supports'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'editor'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'thumbnail'</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>La línea que pone &#8217;supports&#8217; crea una cadena con los campos que soporta la Entrada Personalizada, en este caso el Título (title), el Contenido (editor) y la Imagen Destacada (thumbnail). Podemos ver todos los componentes posibles y más información sobre register_post_type en <a href="http://codex.wordpress.org/Function_Reference/register_post_type">la web de wordpress</a>. Como vemos, podríamos haber añadido  &#8216;author&#8217;, &#8216;excerpt&#8217; o  &#8216;custom-fields&#8217; por ejemplo.</p>
<p>Ahora podemos crear en el directorio de nuestro tema un archivo <strong>producto.php</strong> que recoja todos los productos introducidos y un archivo <strong>single-producto.php</strong> que muestre cada producto individual.  </p>
<p><strong>Archivo producto.php:</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;div id=&quot;container&quot;&gt;
    &lt;div id=&quot;content&quot;&gt;
      <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span> have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
          <span style="color: #000000; font-weight: bold;">&lt;?php</span>
             <span style="color: #000088;">$custom</span> <span style="color: #339933;">=</span> get_post_custom<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: #009900;">&#41;</span><span style="color: #339933;">;</span>
             <span style="color: #000088;">$precio</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$custom</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;precio&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
             <span style="color: #000088;">$fabricante</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$custom</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;fabricante&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
           <span style="color: #000000; font-weight: bold;">?&gt;</span>
           &lt;div id=&quot;post-<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; <span style="color: #000000; font-weight: bold;">&lt;?php</span> post_class<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>&gt;
            &lt;h2 class=&quot;entry-title&quot;&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h2&gt;
             &lt;div class=&quot;entry-meta&quot;&gt;
                   &lt;div class=&quot;entry-content&quot;&gt;
                    <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
                    <span style="color: #000000; font-weight: bold;">&lt;?php</span> 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 class=&quot;caracteristicas&quot;&gt;Precio: <span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$precio</span><span style="color: #000000; font-weight: bold;">?&gt;</span> - Fabricante: <span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$fabricante</span><span style="color: #000000; font-weight: bold;">?&gt;</span> - <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_the_term_list<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: #0000ff;">'plataforma'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Plataforma: '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
                   &lt;/div&gt;
             &lt;/div&gt;
         &lt;/div&gt;
      <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;div&gt;&lt;!-- #content --&gt;
&lt;/div&gt;&lt;!-- #container --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><strong>Ojo: </strong>En la línea p class=&#8221;caracteristicas&#8221; hemos incluido la taxonomía &#8220;Plataforma&#8221; que aún no hemos creado (la creamos más abajo).</p>
<p>Archivo single-producto.php:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> get_header<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
   &lt;div id=&quot;container&quot;&gt;
     &lt;div id=&quot;content&quot;&gt;
       <span style="color: #000000; font-weight: bold;">&lt;?php</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>
       <span style="color: #000000; font-weight: bold;">&lt;?php</span>
         <span style="color: #000088;">$custom</span> <span style="color: #339933;">=</span> get_post_custom<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: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000088;">$precio</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$custom</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;precio&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
         <span style="color: #000088;">$fabricante</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$custom</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;fabricante&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">?&gt;</span>
        &lt;div id=&quot;post-<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; <span style="color: #000000; font-weight: bold;">&lt;?php</span> post_class<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>&gt;
         &lt;h1 class=&quot;entry-title&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> - <span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$precio</span><span style="color: #000000; font-weight: bold;">?&gt;</span> - <span style="color: #000000; font-weight: bold;">&lt;?=</span><span style="color: #000088;">$fabricante</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h1&gt;
          &lt;div class=&quot;entry-meta&quot;&gt;
    	   &lt;div class=&quot;entry-content&quot;&gt;
	     <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	   &lt;/div&gt;
         &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;&lt;!-- #content --&gt;
&lt;/div&gt;&lt;!-- #container --&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> get_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Una vez tengamos todo este código listo podremos introducir nuestros Productos y podremos verlos todos en la url www.nuestraweb.com/Productos gracias a producto.php y podremos ver cada producto en concreto en la url www.nuestraweb.com/Productos/nombre-del-producto gracias a single-producto.php (hay que tener activados los enlaces permanentes. Si sale &#8220;página no encontrada&#8221; volved a grabar los enlaces permanentes ya que a veces necesitan actualizarse).</p>
<h3>Paso 2- Crear los Campos Personalizados</h3>
<p>A continuación vamos a crear los Campos Personalizados Precio y Fabricante para nuestras Entradas Personalizadas. Lo haremos siguiendo <a href="http://net.tutsplus.com/tutorials/wordpress/rock-solid-wordpress-3-0-themes-using-custom-post-types/">este artículo de Nettuts+</a>. Ahora podremos darle a nuestros campos personalizados nombre propios claros para saber lo que es cada uno (en este caso Precio y Fabricante). Para ello añadimos a functions.php este código:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_action(&quot;admin_init&quot;, &quot;admin_init&quot;);
add_action('save_post', 'guardar_precio');
add_action('save_post', 'guardar_fabricante');
&nbsp;
function admin_init(){
  add_meta_box(&quot;prodInfo-meta&quot;, &quot;Opciones Producto&quot;, &quot;meta_options&quot;, &quot;Producto&quot;, &quot;normal&quot;, &quot;low&quot;);
}
function meta_options(){
  global $post;
  $custom = get_post_custom($post-&gt;ID);
  $precio = $custom[&quot;precio&quot;][0];
  $fabricante = $custom[&quot;fabricante&quot;][0];
?&gt;
  &lt;label&gt;Precio:&lt;/label&gt;&lt;input name=&quot;precio&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$precio</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;&lt;br /&gt;&lt;br /&gt;
  &lt;label&gt;Fabricante:&lt;/label&gt;&lt;input name=&quot;fabricante&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$fabricante</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> guardar_precio<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;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
  update_post_meta<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: #0000ff;">&quot;precio&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;precio&quot;</span><span style="color: #009900;">&#93;</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;">function</span> guardar_fabricante<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;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
  update_post_meta<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: #0000ff;">&quot;fabricante&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;fabricante&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>La primera linea indica que cuando se inicialice el panel de administración se llame a la función admin_init(). Esta función dice a WordPress que añada un área llamada &#8220;Opciones Producto&#8221; para cualquier Entrada Personalizada llamada Producto y que use la función meta_options() para mostrar los campos del formulario. Puedes <a href="http://codex.wordpress.org/Function_Reference/add_meta_box">leer más sobre add_meta_box aquí</a>. meta_options() obtendrá entonces cualquier valor preexistente y lo mostrará en el formulario. Las dos lineas de acción que siguen a la primera línea hacen que cuando se grabe una entrada se llame a las funciones guardar_precio() y guardar_fabricante() que utilizan update_post_meta() para añadir o actualizar los campos personalizados &#8220;Precio&#8221; y &#8220;Fabricante&#8221;.</p>
<h3>Paso 3 &#8211; Crear Taxonomías personalizadas asociadas</h3>
<p>Una vez tengamos nuestras Entradas Personalizadas es posible que queramos tener una serie de Taxonomías que nos ayuden a clasificar los distintos productos según determinadas categorías. Podemos ver más información sobre las taxonomías en el artículo <a href="http://www.emenia.es/taxonomias-en-wordpress/">Taxonomías en Wordpress</a>.</p>
<p>Vamos a crear, como dijimos, una Taxonomía personalizada llamada &#8220;Plataforma&#8221;, donde podremos poner si el juego es para PC CD-ROM, Playstation 3, etc&#8230; Para ello escribimos en functions.php:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;plataforma&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Producto&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;hierarchical&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;label&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Plataforma&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;singular_label&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Plataforma&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;rewrite&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Puedes encontrar más información sobre la función register_taxonomy() <a href="http://codex.wordpress.org/Function_Reference/register_taxonomy">en la web de Wordpress</a>. Aquí creamos una nueva Taxonomía llamada &#8220;Plataforma&#8221; y la asociamos a la entrada personalizada &#8220;Producto&#8221;. Para poder ver luego la taxonomía escribiríamos (como hemos visto más arriba en producto.php):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_the_term_list<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: #0000ff;">'plataforma'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Plataforma: '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Paso 4 &#8211; Crear la tabla de productos en el panel de administración</h3>
<p>Vimos al principio de este artículo que al hacer click sobre Editar en Producto salía una tabla con el nombre de cada producto, su descripción, precio, fabricante y plataforma. Esto no se crea por defecto. Para conseguirlo, <a href="http://net.tutsplus.com/tutorials/wordpress/rock-solid-wordpress-3-0-themes-using-custom-post-types/">tal y como vemos en el mismo artículo de nettuts+</a>, hay que añadir en functions.php:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;manage_edit-Producto_columns&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;prod_edit_columns&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
add_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;manage_posts_custom_column&quot;</span><span style="color: #339933;">,</span>  <span style="color: #0000ff;">&quot;prod_custom_columns&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> prod_edit_columns<span style="color: #009900;">&#40;</span><span style="color: #000088;">$columns</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$columns</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
      <span style="color: #0000ff;">&quot;cb&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;&lt;input type=<span style="color: #000099; font-weight: bold;">\&quot;</span>checkbox<span style="color: #000099; font-weight: bold;">\&quot;</span> /&gt;&quot;</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">&quot;title&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Nombre del Producto&quot;</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">&quot;descripcion&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Descripción&quot;</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">&quot;precio&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Precio&quot;</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">&quot;plataforma&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Plataforma&quot;</span><span style="color: #339933;">,</span>
      <span style="color: #0000ff;">&quot;fabricante&quot;</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Fabricante&quot;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$columns</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> prod_custom_columns<span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$column</span><span style="color: #009900;">&#41;</span>
       <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;descripcion&quot;</span><span style="color: #339933;">:</span>
	   the_excerpt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	   <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;precio&quot;</span><span style="color: #339933;">:</span>
	   <span style="color: #000088;">$custom</span> <span style="color: #339933;">=</span> get_post_custom<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	   <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$custom</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;precio&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	   <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;fabricante&quot;</span><span style="color: #339933;">:</span>
	   <span style="color: #000088;">$custom</span> <span style="color: #339933;">=</span> get_post_custom<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	   <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$custom</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">&quot;fabricante&quot;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	   <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">&quot;plataforma&quot;</span><span style="color: #339933;">:</span>
	   <span style="color: #b1b100;">echo</span> get_the_term_list<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: #0000ff;">'plataforma'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	   <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>En prod_edit_columns() tenemos un array donde los índices (keys) de cada variable se usan para referenciar cierta información de las entradas que definimos en la segunda función, prod_custom_columns() y donde los valores son las cabeceras de las columnas. En prod_edit_columns() hay 6 columnas pero sólo mostramos 4 en prod_custom_columns() ya que ‘cb’ y ‘title’ son parte de los índices por defecto de Wordpress para los que ya tiene asociaciones creadas.</p>
<p>Bueno, ¡y eso sería todo! Con este código adecuadamente incluído podemos tener las pantallas que veíamos al principio del artículo. Pero como véis hay mucho campo para ampliar las posibilidades que se nos ofrecen con las Entradas Personalizadas. Aquí hemos hecho una lista de Productos, pero podría haber sido las habitaciones de un hotel, una lista de canciones de distintos autores, una lista de libros o cualquier cosa que se nos ocurra.</p>
<h3>Otras lecturas recomendadas</h3>
<p><a href="http://somadesign.ca/projects/smarter-custom-post-types/">Smarter Custom Post Types</a><br />
<a href="http://net.tutsplus.com/tutorials/wordpress/rock-solid-wordpress-3-0-themes-using-custom-post-types/">Rock-Solid WordPress 3.0 Themes using Custom Post Types </a><br />
<a href="http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress">Custom post types in WordPress</a><br />
<a href="http://justintadlock.com/archives/2010/02/02/showing-custom-post-types-on-your-home-blog-page">Showing custom post types on your home/blog page</a><br />
<a href="http://kovshenin.com/archives/custom-post-types-in-wordpress-3-0/">Custom Post Types in WordPress 3.0</a><br />
<a href="http://kovshenin.com/archives/extending-custom-post-types-in-wordpress-3-0/">Extending Custom Post Types in WordPress 3.0</a><br />
<a href="http://net.tutsplus.com/tutorials/wordpress/introducing-wordpress-3-custom-taxonomies/">Introducing WordPress 3 Custom Taxonomies</a></p>
<div id="crp_related"><h3>Artículos relacionados:</h3><ul><li><a href="http://www.emenia.es/taxonomias-en-wordpress/" rel="bookmark" class="crp_title">Taxonomías en Wordpress</a></li><li><a href="http://www.emenia.es/nuevo-en-wordpress-2-9-miniaturas-de-entrada-post-thumbnails/" rel="bookmark" class="crp_title">Nuevo en Wordpress 2.9: Miniaturas de Entrada (Post Thumbnails)</a></li><li><a href="http://www.emenia.es/recopilacion-de-45-trucos-para-wordpress/" rel="bookmark" class="crp_title">Recopilación de 45 trucos para Wordpress</a></li><li><a href="http://www.emenia.es/barra-lateral-diferente-para-cada-pagina-en-wordpress/" rel="bookmark" class="crp_title">Barra Lateral diferente para cada página en Wordpress</a></li><li><a href="http://www.emenia.es/como-separar-los-articulos-por-categorias-en-wordpress/" rel="bookmark" class="crp_title">Cómo separar los artículos por categorías en Wordpress</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emenia.es/lista-productos-wordpress-3/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Funciones útiles para functions.php en Wordpress</title>
		<link>http://www.emenia.es/funciones-utiles-para-functions-php-en-wordpress/</link>
		<comments>http://www.emenia.es/funciones-utiles-para-functions-php-en-wordpress/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 07:11:27 +0000</pubDate>
		<dc:creator>Juan Diaz-Bustamante</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.emenia.es/?p=764</guid>
		<description><![CDATA[El blog <a href="http://ayudawordpress.com" title="Ir a ayudawordpress.com"> ayudawordpress.com</a>, centrado en artículos sobre Wordpress, ha publicado hoy un artículo mío que quizás os pueda interesar. Se llama <a href=" 35 Funciones útiles para functions.php en Wordpress" title="Ir al artículo">35 Funciones útiles para functions.php en Wordpress</a> y recoje 35 funciones útiles (algunas más que otras) para incluir en el archivo functions.php de nuestro tema de Wordpress. Son especialmente útiles si creamos nuestro tema desde cero y le damos una funcionalidad propia.

Es el primer artículo que escribo en ayudawordpres.com, ha sido una buena experiencia que espero repetir cuando tenga algún otro artículo sobre Wordpress.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.emenia.es%2Ffunciones-utiles-para-functions-php-en-wordpress%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.emenia.es%2Ffunciones-utiles-para-functions-php-en-wordpress%2F&amp;source=JuanDBB_Emenia&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>El blog <a href="http://ayudawordpress.com" title="Ir a ayudawordpress">ayudawordpress.com</a>, centrado en artículos sobre Wordpress, ha publicado hoy un artículo mío que quizás os pueda interesar. Se llama <a href="http://ayudawordpress.com/35-funciones-utiles-para-functions-php-en-wordpress/#more-7607" title="Ir al artículo">35 Funciones útiles para functions.php en Wordpress</a> y recoje 35 funciones útiles (algunas más que otras) para incluir en el archivo functions.php de nuestro tema de Wordpress. Son especialmente útiles si creamos nuestro tema desde cero y le damos una funcionalidad propia.</p>
<p>Es el primer artículo que escribo en ayudawordpres.com, ha sido una buena experiencia que espero repetir cuando tenga algún otro artículo sobre Wordpress.</p>
<div id="crp_related"><h3>Artículos relacionados:</h3><ul><li><a href="http://www.emenia.es/la-funcion-body_class-en-wordpress/" rel="bookmark" class="crp_title">Clases dinámicas en body utilizando la función body_class() de Wordpress</a></li><li><a href="http://www.emenia.es/como-limitar-el-numero-de-palabras-en-the_content-o-the_excerpt-en-wordpress/" rel="bookmark" class="crp_title">Cómo limitar el número de palabras en the_content o the_excerpt en Wordpress</a></li><li><a href="http://www.emenia.es/como-utilizar-un-fondo-aleatorio-para-nuestra-web/" rel="bookmark" class="crp_title">Como utilizar un fondo aleatorio para nuestra web</a></li><li><a href="http://www.emenia.es/nuevo-en-wordpress-2-9-miniaturas-de-entrada-post-thumbnails/" rel="bookmark" class="crp_title">Nuevo en Wordpress 2.9: Miniaturas de Entrada (Post Thumbnails)</a></li><li><a href="http://www.emenia.es/barra-lateral-diferente-para-cada-pagina-en-wordpress/" rel="bookmark" class="crp_title">Barra Lateral diferente para cada página en Wordpress</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emenia.es/funciones-utiles-para-functions-php-en-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Crea tu propia red social con Wordpress y BuddyPress &#8211; Introducción</title>
		<link>http://www.emenia.es/crea-tu-propia-red-social-con-wordpress-y-buddypress-introduccion/</link>
		<comments>http://www.emenia.es/crea-tu-propia-red-social-con-wordpress-y-buddypress-introduccion/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 09:22:07 +0000</pubDate>
		<dc:creator>Juan Diaz-Bustamante</dc:creator>
				<category><![CDATA[BuddyPress]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.emenia.es/?p=728</guid>
		<description><![CDATA[Vamos a ver cómo crear nuestra propia red social gracias a <strong>Wordpress</strong> y a <strong>BuddyPress</strong>. BudyPress es un impresionante plugin de Wordpress que transforma nuestra instalación de Wordpress en una potente red social. ]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.emenia.es%2Fcrea-tu-propia-red-social-con-wordpress-y-buddypress-introduccion%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.emenia.es%2Fcrea-tu-propia-red-social-con-wordpress-y-buddypress-introduccion%2F&amp;source=JuanDBB_Emenia&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Vamos a ver cómo crear nuestra propia red social gracias a <strong>Wordpress</strong> y a <strong>BuddyPress</strong>. BudyPress es un impresionante plugin de Wordpress que transforma nuestra instalación de Wordpress en una potente red social. Antiguamente BuddyPress sólo funcionaba sobre Wordpress MU (Wordpress multiusuario), pero ahora<strong> desde BudyPress 1.2 <a href="http://wordpress.org/development/2010/02/buddypress-for-one-and-all-3/" title="Ir a la noticia">podemos ya instalarlo</a> sobre una versión normal de Wordpress</strong> (eso sí, hasta que no salga Wordpress 3.0 no podremos aprovechar la posibilidad de que los usuarios tengan sus propios blogs). Para empezar tenemos que:</p>
<p><img src="http://www.emenia.es/wp-content/uploads/2010/03/web.jpg" alt="" title="web" width="550" height="444" class="alignleft size-full wp-image-742" /><br />
<br class="clear" /><br />
1) Instalar Wordpress<br />
2) Instalar BuddyPress desde Plugins/Añadir, buscando BuddyPress. Alternativamente podemos bajarnos la última versión de <a href="http://buddypress.org/" title="Ir a Buddypress">BuddyPress</a>, decomprimirla y subirla a la carpeta de plugins.<br />
3) Tenemos que cercionarnos que tenemos activados los enlaces permanentes en nuestra instalación de Wordpress.<br />
4) Ahora en el gestor de Wordpress veremos que podemos activar BuddyPress desde la sección de plugins.<br />
5) Seleccionar un tema compatible con Buddypress. Desde el administrador de Wordpress entramos en Apariencia y seleccionamos el tema por defecto de Buddypress (Default).<br />
6) Traducir Buddypress al Castellano (doy por supuesto que tenemos ya Wordpress en Castellano). Para ello, buscamos dentro de la carpeta de wp-content/plugins la carpeta de buddypress. Dentro de esta hay una carpeta llamada bp-languages. Aquí copiamos el archivo buddypress-es_ES.mo que obtenemos de <a href="http://www.buddypress-es.com/noticias/descargas/" title="Ir a buddypress-es.com">buddypress-es.com</a>.</p>
<p>Ahora ya deberíamos tener Buddypress funcionando. Como podemos ver, tenemos una red social ya de inicio bastante potente. A partir de aquí nos toca trabajar para dar a nuestra red social una apariencia y funcionamiento que se ajuste a nuestras preferencias.</p>
<p>Para <strong>configurar las opciones de Buddypress </strong>podéis ver que en el administrador de Wordpress hay ahora un apartado entero de Buddypress:</p>
<p><a href="http://www.emenia.es/wp-content/uploads/2010/03/opciones.jpg"><img src="http://www.emenia.es/wp-content/uploads/2010/03/opciones.jpg" alt="" title="opciones" width="156" height="372" class="alignleft size-full wp-image-756" /></a><br />
<br class="clear" /></p>
<p>Si además queremos crear un nuevo tema lo mejor, y hasta que tengamos un control grande sobre Buddypress y podamos crear un tema desde cero, es trabajar y modificar el tema que viene por defecto. Para ello los desarrolladores de Buddypress nos recomiendan que <a href="http://codex.buddypress.org/how-to-guides/building-a-buddypress-child-theme/" title="Ir al artículo">extendamos ese tema por defecto</a> (llamado default). Esto nos permitirá heredar los estilos, los scripts, AJAX etc.. del original que queramos conservar y sobreescribir lo que queramos cambiar. </p>
<p><strong>¿Cómo lo extendemos?</strong> Primero de todo creamos una carpeta en wp-content/themes con el nombre de nuestro tema, como si se tratara de un tema normal de Wordpress. En esta carpeta incluiremos sólo aquellas partes de nuestro tema (estilos, templates, etc..) <strong>que vayan a sobreescribir lo existente en el tema por defecto de BuddyPress</strong> (que se encuentra en wp-content/plugins/buddypress/bp-themes/bp-default, es decir, no en donde habitualmente tenemos nuestros temas en Wordpress).</p>
<p>Un buen método para sobreescribir cualquier template es copiarlo desde la carpeta del tema default de Buddypress a la carpeta de nuestro tema, y desde ahí cambiarlo (sin tocar el original. Es peligroso funcionar desde el original directamente ya que en cualquier actualización este se sobreescribirá entero). También podrás añadir en la nueva carpeta de tu tema cualquier archivo nuevo y propio de CSS, php, javascript, etc.. <strong>Cualquier archivo sobreescribirá al original del mismo nombre</strong>.</p>
<p><strong>El primer paso es crear la hoja de estilos nueva</strong>. La crearemos dentro de la nueva carpeta de nuestro tema (supongamos que nuestro tema se llama Test, y estará en /wp-content/themes/test). En esta carpeta crearemos un archivo de estilos al que llamaremos “style.css”. Esta será la hoja de estilos de nuestro nuevo tema para dar una apariencia personalizada a nuestra nueva red social.</p>
<p>Abre “style.css” y escribe:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">/*
Theme Name: BuddyPress Test
Theme URI: http://dondesea/
Description: Nuevo tema para BuddyPress.
Version: 1.0
Author: Nuestro Nombre
Author URI: http://nuestaweb/
Template: bp-default
Tags: buddypress
*/</span>
<span style="color: #808080; font-style: italic;">/* Para heredar los archivos de estilo. Si quieres crear todo de cero no la incluyas */</span>
<span style="color: #a1a100;">@import url( ../../plugins/buddypress/bp-themes/bp-default/_inc/css/default.css );</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* Para heredar los estilos de la barra de administración. Si quieres crear todo de cero no la incluyas */</span>
<span style="color: #a1a100;">@import url( ../../plugins/buddypress/bp-themes/bp-default/_inc/css/adminbar.css );</span></pre></td></tr></table></div>

<p>En <strong>&#8220;Template:&#8221;</strong> vemos como le decimos a Wordpress que queremos utilizar el tema por defecto de Wordpress (bp-default) como &#8220;tema padre&#8221; y heredar todos los templates y estilos de este. En <strong>&#8220;Tags:&#8221; </strong>pone buddypress, lo cual indica a Wordpress que estamos usando un tema de buddypress.</p>
<p>Graba el archivo y activa el nuevo tema (que hemos llamado Test) desde el administrador de Wordpress (en Apariencia). </p>
<p>A partir de aquí, en tu hoja de estilos nueva puedes sobreescribir cualquier estilo del original. Como comentaba antes cualquier archivo que grabes en la carpeta del nuevo tema que tenga igual nombre que el del original (por ejemplo, header.php) se cargará en lugar del original. <strong>Sólo hay una excepción a esta regla:</strong> aunque crees un archivo functions.php nuevo el original también se cargará.</p>
<p>Bueno, pues ha llegado el momento de enredar con nuestra nueva red social, con sus configuraciones, estilos, templates, etc&#8230;  En siguientes artículos entraré un poco más en detalle en el funcionamiento interno de BuddyPress.</p>
<h3>Webs recomendadas</h3>
<p><a href="http://buddypress.org/" title="Ir a la web de BuddyPress">Web oficial de BuddyPress</a><br />
<a href="http://codex.buddypress.org/" title="Ir a la documentación de BuddyPress">Documentación de BuddyPress en la web oficial</a><br />
<a href="http://buddypress.org/extend/plugins/" title="Plugins de BuddyPress">Plugins de BuddyPress en la web oficial</a><br />
<a href="http://www.buddypress-es.com/" title="Ir a BuddyPress-es.com">Buddypress-es.com</a>, Buddypress en Castellano<br />
<a href="http://wpmu.org/" title="Ir a wpmu.org">wpmu.org</a><br />
<a href="http://premium.wpmudev.org/" title="Ir a wpmudev.org">wpmudev.org</a></p>
<div id="crp_related"><h3>Artículos relacionados:</h3><ul><li><a href="http://www.emenia.es/funciones-utiles-para-functions-php-en-wordpress/" rel="bookmark" class="crp_title">Funciones útiles para functions.php en Wordpress</a></li><li><a href="http://www.emenia.es/primeros-pasos-tras-una-nueva-instalacion-de-wordpress/" rel="bookmark" class="crp_title">Primeros pasos tras una nueva instalación de Wordpress</a></li><li><a href="http://www.emenia.es/curso-de-jquery-2-selectores-primera-parte/" rel="bookmark" class="crp_title">Curso de jQuery (2): Selectores, Primera Parte</a></li><li><a href="http://www.emenia.es/curso-de-jquery-introduccion-1/" rel="bookmark" class="crp_title">Curso de jQuery (1): Introducción</a></li><li><a href="http://www.emenia.es/curso-de-jquery-4-selectores-tercera-parte/" rel="bookmark" class="crp_title">Curso de jQuery (4): Selectores, Tercera Parte</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emenia.es/crea-tu-propia-red-social-con-wordpress-y-buddypress-introduccion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nuevo en Wordpress 2.9: Miniaturas de Entrada (Post Thumbnails)</title>
		<link>http://www.emenia.es/nuevo-en-wordpress-2-9-miniaturas-de-entrada-post-thumbnails/</link>
		<comments>http://www.emenia.es/nuevo-en-wordpress-2-9-miniaturas-de-entrada-post-thumbnails/#comments</comments>
		<pubDate>Mon, 15 Mar 2010 21:47:29 +0000</pubDate>
		<dc:creator>Juan Diaz-Bustamante</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.emenia.es/?p=707</guid>
		<description><![CDATA[Una de las principales novedades que nos ha ofrecido Wordpress 2.9 es la posibilidad de crear Miniaturas de Entrada (en inglés Post Thumbnails). ¿Qué son las Miniaturas de Entrada? Son las imágenes que veréis en muchos blogs asociadas a las distintas entradas de dicho blog en su página principal. Veremos cómo incluirlas en nuestros temas.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.emenia.es%2Fnuevo-en-wordpress-2-9-miniaturas-de-entrada-post-thumbnails%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.emenia.es%2Fnuevo-en-wordpress-2-9-miniaturas-de-entrada-post-thumbnails%2F&amp;source=JuanDBB_Emenia&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Una de las principales novedades que nos ha ofrecido Wordpress 2.9 es la posibilidad de crear Miniaturas de Entrada (en inglés Post Thumbnails). ¿Qué son las Miniaturas de Entrada? Son las imágenes que veréis en muchos blogs asociadas a las distintas entradas de dicho blog en su página principal. Veamos por ejemplo nettuts+:</p>
<p><a href="http://www.emenia.es/wp-content/uploads/2010/03/nettuts.jpg"><img src="http://www.emenia.es/wp-content/uploads/2010/03/nettuts.jpg" alt="" title="nettuts" width="550" height="513" class="alignleft size-full wp-image-708" /></a></p>
<p><br class="clear" /><br />
Vemos que cada entrada tiene asociada a su izquierda una imagen (marcada con un círculo rojo) que ayuda a describir mejor el artículo asociado, además de mejorar la imagen general del blog. Hasta ahora la manera más habitual de conseguir situar estas miniaturas era mediante <strong>Campos Personalizados</strong>. Ahora hay ya una funcionalidad completa e independiente para crear las Miniaturas de Entrada. Vamos a verla en detalle.</p>
<p><strong>Para poder usar las Miniaturas de entrada tenemos que activarlas</strong>. Esto lo hacemos desde el archivo functions.php de nuestro tema. Escribimos:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'add_theme_support'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> add_theme_support<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post-thumbnails'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Simplemente indica que si existe la función<em> <strong>&#8216;add_theme_support&#8217;</strong></em> se ejecute <strong><em>add_theme_support(&#8216;post-thumbnails&#8217;)</em></strong>. Lo habilitará tanto para páginas como para entradas. Si lo quieres sólo para uno de ellos:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_theme_support<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'post-thumbnails'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'post'</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;">// Sólo para entradas</span>
add_theme_support<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'post-thumbnails'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'page'</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;">// Sólo para páginas</span></pre></td></tr></table></div>

<p>Ahora al ir a escribir o a editar una entrada, tendremos en la columna de la derecha una nueva ventana, llamada, como no, Miniatura de Entrada:</p>
<p><a href="http://www.emenia.es/wp-content/uploads/2010/03/miniatura1.jpg"><img src="http://www.emenia.es/wp-content/uploads/2010/03/miniatura1.jpg" alt="" title="miniatura1" width="292" height="76" class="alignleft size-full wp-image-712" /></a><br />
<br class="clear" /><br />
Si hacemos click sobre <strong><em>Establecer miniatura</em></strong> aparecerá la pantalla habitual para añadir una imagen. La seleccionamos y veremos entonces:</p>
<p><a href="http://www.emenia.es/wp-content/uploads/2010/03/miniatura21.jpg"><img src="http://www.emenia.es/wp-content/uploads/2010/03/miniatura21.jpg" alt="" title="miniatura2" width="500" height="667" class="alignleft size-full wp-image-716" /></a><br />
<br class="clear" /><br />
En la parte de abajo, junto a Insertar en la entrada, vemos el enlace <strong><em>Usar como miniatura</em></strong>. Ese es el enlace sobre el que hay que hacer click. Entonces veremos que en el cuadro de Miniatura de entrada aparece la imagen que hemos seleccionado:<br />
<a href="http://www.emenia.es/wp-content/uploads/2010/03/miniatura3.jpg"><img src="http://www.emenia.es/wp-content/uploads/2010/03/miniatura3.jpg" alt="" title="miniatura3" width="291" height="214" class="alignleft size-full wp-image-717" /></a><br />
<br class="clear" /><br />
Ahora ya tendremos la imagen asociada a nuestro artículo. Pero nos queda un último paso: tenemos que incluir unas líneas dentro del loop para que se muestre la miniatura de entrada. Para ello tonamos el archivo que muestre las entradas en nuestro tema (por ejemplo index.php) y buscamos el loop, es decir, lo incluido entre</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #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>
// Aquí va lo que se llama el loop, es decir un bucle que muestra 
// las entradas de nuestro blog
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Es ahí, dentro del loop, donde añadiremos un código que va a añadir la miniatura de cada entrada. Símplemente hay que escribir esta línea:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Un loop sencillo podría parecerse más o menos a esto:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #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;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h1&gt; // Titulo de la entrada
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<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> // Miniatura de entrada
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> // El contenido de la entrada
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Si, para estar seguros, queremos saber si la entrada o artículo en cuestión tiene una miniatura asociada, podemos hacer:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> has_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #666666; font-style: italic;">// esta entrada tiene una miniatura, pondremos aquí</span>
<span style="color: #666666; font-style: italic;">// un código que muestre la miniatura:</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<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>
} else {
// esta entrada no tiene miniatura, podemos poner aquí
// algo alternativo, por ejemplo mostrar la miniatura mediante campos
// personalizados, como se hacía anteriormente, o una imagen
// genérica.
}
?&gt;</pre></td></tr></table></div>

<p>Se puede seleccionar también el tamaño de la miniatura:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">// Tamaño pequeño:
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'thumbnail'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
// Tamaño mediano:
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'medium'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
// Tamaño grande:
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'large'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
// Especificando el tamaño:
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">225</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">225</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>También se pueden añadir atributos como title y alt, así como una clase que nos servirá para dar estilo con nuestra hoja CSS:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">// Aplicando una clase que llamaremos clase_miniatura en este caso:
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'medium'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'clase_miniatura'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
// Definiendo los atributos title y alt:
<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'medium'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'class'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'clase_miniatura'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'alt'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'atributo_alt'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'atributo_title'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>En el caso de no asignar ninguna clase podemos dar estilo a la miniatura con <strong><em>.wp-post-image {}</em></strong></p>
<p>Volvamos de nuevo al archivo functions.php de nuestro tema. Vimos al principio de todo que las Miniaturas teníamos que activarlas en dicho archivo. Podemos además especificar el tamaño de las miniaturas:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// Miniaturas redimensionadas a 50x50px </span>
set_post_thumbnail_size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">50</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// Miniaturas cortadas a 50x50px</span>
set_post_thumbnail_size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>O asignar un tamaño concreto (también en functions.php):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_image_size<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'custom-thumbnail'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">300</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Que usaríamos así dentro del loop (por ejemplo en index.php):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> the_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'custom-thumbnail'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Si queremos que en functions.php esté todo este código que hemos visto incluído de manera segura (es decir, tras comprobar que existe esa funcionalidad en nuestra versión de Wordpress), escribiríamos:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'add_theme_support'</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;">// a partir de WP 2.9</span>
add_theme_support<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post-thumbnails'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// activa las miniaturas</span>
set_post_thumbnail_size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// especifica su tamaño</span>
add_image_size<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'custom-thumbnail'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">500</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// tamaño concreto</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Y para más seguridad, podemos poner como vimos antes, dentro del loop, el condicional que muestra las miniaturas. En el caso de que esta no exista podemos poner un plan alternativo, como puede ser una imagen de un campo personalizado:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'has_post_thumbnail'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>has_post_thumbnail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
the_post_thumbnail<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: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$postimageURL</span> <span style="color: #339933;">=</span> get_post_meta<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: #0000ff;">'post-image'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</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;">$postimageURL</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;img src=&quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$postimageURL</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&quot; alt=&quot;&quot; /&gt;'</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<h3>Lecturas recomendadas</h3>
<p>bocabit.com: <a href="http://bocabit.com/tecnologia/informatica/tutorial/todo-sobre-las-miniaturas-thumbnails-de-wordpress-2-9.php" title="Ir al artículo">Todo sobre las miniaturas (thumbnails) de Wordpress 2.9</a><br />
Mark Jaquith: <a href="http://markjaquith.wordpress.com/2009/12/23/new-in-wordpress-2-9-post-thumbnail-images/" title="Ir al artículo">New in WordPress 2.9: Post Thumbnail Images</a><br />
Justin Tadlock: <a href="http://justintadlock.com/archives/2009/11/16/everything-you-need-to-know-about-wordpress-2-9s-post-image-feature" title="Ir al artículo">Everything you need to know about WordPress 2.9’s post image feature</a></p>
<div id="crp_related"><h3>Artículos relacionados:</h3><ul><li><a href="http://www.emenia.es/taxonomias-en-wordpress/" rel="bookmark" class="crp_title">Taxonomías en Wordpress</a></li><li><a href="http://www.emenia.es/como-limitar-el-numero-de-palabras-en-the_content-o-the_excerpt-en-wordpress/" rel="bookmark" class="crp_title">Cómo limitar el número de palabras en the_content o the_excerpt en Wordpress</a></li><li><a href="http://www.emenia.es/lista-productos-wordpress-3/" rel="bookmark" class="crp_title">Crear una lista de productos con Wordpress 3.0 usando Entradas personalizadas, campos personalizados y taxonomías</a></li><li><a href="http://www.emenia.es/la-funcion-body_class-en-wordpress/" rel="bookmark" class="crp_title">Clases dinámicas en body utilizando la función body_class() de Wordpress</a></li><li><a href="http://www.emenia.es/recopilacion-de-45-trucos-para-wordpress/" rel="bookmark" class="crp_title">Recopilación de 45 trucos para Wordpress</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emenia.es/nuevo-en-wordpress-2-9-miniaturas-de-entrada-post-thumbnails/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Taxonomías en Wordpress</title>
		<link>http://www.emenia.es/taxonomias-en-wordpress/</link>
		<comments>http://www.emenia.es/taxonomias-en-wordpress/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 12:53:23 +0000</pubDate>
		<dc:creator>Juan Diaz-Bustamante</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://www.emenia.es/?p=568</guid>
		<description><![CDATA[Por defecto, Wordpress incluye tres taxonomías: categoría, etiquetas y categoría de los enlaces. En este artículo veremos cómo enriquecer las taxonomías de nuestro tema de Wordpress creando nuestras propias Taxonomías.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.emenia.es%2Ftaxonomias-en-wordpress%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.emenia.es%2Ftaxonomias-en-wordpress%2F&amp;source=JuanDBB_Emenia&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>El uso de <strong>Categorías</strong> y de <strong>Etiquetas</strong> (Tags en Inglés) es muy habitual en Wordpress. A la hora de crear una nueva entrada podemos asignarle una categoría (normalmente una categoría por entrada) y uno o varias etiquetas (normalmente varias etiquetas por entrada). Esto nos permite clasificar la información que estamos publicando para que luego sea más sencillo acceder a ella en función de las necesidades del usuario.</p>
<p>Tanto las Categorías como las Etiquetas son <strong>Taxonomías</strong>. ¿Qué es una Taxonomía? Veamos lo que dice el diccionario:</p>
<p><em><strong>taxonomía.</strong> Ciencia que trata de los principios, métodos y fines de la clasificación. Se aplica en particular, dentro de la biología, para la ordenación jerarquizada y sistemática, con sus nombres, de los grupos de animales y de vegetales. <strong>2.</strong> Por ext., clasificación.</em></p>
<p>Por defecto, Wordpress incluye tres taxonomías: categoría, etiquetas y categoría de los enlaces. En este artículo veremos cómo enriquecer las taxonomías de nuestro tema de Wordpress creando nuestras propias Taxonomías.</p>
<p>Desde Wordpress 2.8 es mucho más sencillo <strong>crear Taxonomías propias (Custom Taxonomies en Inglés)</strong> que nos pueden dar más flexibilidad que las tradicionales Categorías y Etiquetas. Esto puede sernos de utilizad para entradas que requieren un número alto de criterios de clasificación, de tal forma que las Categorías y las Etiquetas se nos queden cortas. </p>
<p>Por ejemplo, imaginémonos que tenemos una web de música y queremos introducir canciones y clasificarlas por Artista, Album, Género, Epoca, Autor, Duración, etc&#8230; Necesitamos la ayuda de las Taxonomías creadas por el usuario. Veremos que funcionan de manera muy parecida a las etiquetas.</p>
<p>Sigamos con el ejemplo de la web de música. Supongamos que tenemos esta canción:<br />
Shine on your Crazy Diamond<br />
Artista: Pink Floyd<br />
Album: Wish you were here<br />
Género: Rock Progresivo<br />
Autor: Pink Floyd<br />
Duración: 13:32 minutos<br />
Fecha: 1975</p>
<p>La idea es poder fijar toda esta información a una entrada que realices sobre esta canción de forma parecida a como lo harías con las etiquetas. Para empezar tienes que <strong>registrar las taxonomías</strong> para luego poder utilizarlas. Esto lo haces en el archivo <strong>functions.php </strong>de tu tema de Wordpress. Escribríamos:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">function</span> taxonomias_propias<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'artista'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Artista'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'album'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Album'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'genero'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Género'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'autor'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Autor'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'duracion'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Duración'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fecha'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Fecha'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</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;">'init'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'taxonomias_propias'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Vamos a ver en detalle qué hemos hecho. Tomemos la primera taxonomía, <strong><em>artista</em></strong>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">register_taxonomy<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'artista'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
         <span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Artista'</span><span style="color: #339933;">,</span>
         <span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong><em>artista</em></strong> le dice a Wordpress cuál es el nombre de la Taxonomía. </p>
<p><strong><em>post</em></strong> indica el tipo de objeto sobre el que se aplica la Taxonomía, en este caso entradas (post). <strong>Más abajo veremos cómo crear taxonomías en páginas. </strong></p>
<p><strong><em>hierarchical</em></strong> indica si los términos de la taxonomía van a estar jerarquizados (las categorías lo estan, las etiquetas no). Lo ponemos como false (falso) para que se comporten como las etiquetas.</p>
<p><strong><em>Artista</em></strong> es el nombre de la taxonomía tal y como queremos que aparezca en el panel de administración de Wordpress. </p>
<p><strong><em>query_var</em></strong> permite saber a WordPress si vas a querer poder seleccionar artículos utilizando la taxonomía. Más adelante veremos cómo. Ponemos TRUE (es decir, que sí vamos a querer poder hacerlo).</p>
<p><strong><em>rewrite</em></strong> es para si quieres que Wordpress ofrezca urls amigables cuando se vea una página o archivo de una taxonomía (por ejemplo www.tusitio.es/autor/pink-floyd). Como sí queremos, ponemos TRUE (cierto).</p>
<p>Bien, ya hemos registrado nuestras taxonomías propias en el archivo functions.php de nuestro tema. Ahora si entramos en el administrador de Wordpress y abrimos o creamos una nueva entrada veremos que la columna lateral derecha (donde están las categorías y las etiquetas) ha cambiado. Ahora veremos (tengo una instalación de Wordpress en inglés, pero si lo tenéis en Castellano os saldrá bien):</p>
<p><a href="http://www.emenia.es/wp-content/uploads/2010/03/taxonomies-1.jpg"><img src="http://www.emenia.es/wp-content/uploads/2010/03/taxonomies-1.jpg" alt="" title="Taxonomías Propias" width="300" height="792" class="alignleft size-full wp-image-670" /></a><br />
<br class="clear" /></p>
<p>Veremos que en cada casilla de cada nueva taxonomía podemos añadir una nueva etiqueta. Si, el funcionamiento ahora es como el de las etiquetas normales, lo que pasa es que ahora tenemos varios grupos personalizados de etiquetas.</p>
<p>También saldrás las taxonomías nuevas en el menú de la izquierda, al desplegar Entradas.</p>
<p>Una vez publicada la entrada podemos acceder directamente, por ejemplo, a </p>
<p>http://www.tusitio.es/autor/pink-floyd/</p>
<p>Estas nuevas URLs utilizarán archive.php de tu tema de Wordpress para mostrar todas las entradas que correspondan a esa taxonomía. </p>
<p>Si queremos <strong>mostrar una nube de etiquetas</strong> de una taxonomía en concreto (por ejemplo todos los Autores) lo haríamos con este código en cualquier sítio de cualquier archivo de nuestro tema:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;h3&gt;Autores&lt;/h3&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_tag_cloud<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'taxonomy'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'autor'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'number'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>En vez de autor pondríamos el nombre de la taxonomía que queramos, y en número (number) el número de etiquetas a mostrar de esa taxonomía (si ponemos 0, como en este caso, salen todas).</p>
<p>Si queremos que salgan<strong> todas las taxonomías y su nube de etiquetas</strong> podemos seguir las indicaciones de <a href="http://justintadlock.com/archives/2009/05/02/creating-a-page-template-that-lists-all-of-your-wordpress-taxonomies" title="Ir al artículo">justintadlock.com</a>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_taxonomies</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wp_taxonomies</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$wp_taxonomies</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tax</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
		&lt;h2 class=&quot;taxonomy-label&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$tax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">label</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h2&gt;
&nbsp;
		&lt;p class=&quot;taxonomy-cloud&quot;&gt;
			<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_tag_cloud<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'taxonomy'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$tax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'number'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
		&lt;/p&gt;&lt;!-- .taxonomy-cloud --&gt;
&nbsp;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endforeach</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Para <strong>mostrar todas las entradas que tengan una etiqueta concreta</strong> de una de nuestras taxonomías (por ejemplo, las 15 primeras entradas entradas con autor Pink Floyd) tendríamos que situar este código antes del loop de uno de los archivos de nuestro tema:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> query_posts<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'autor'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Pink Floyd'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'showposts'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">15</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
// Y ahora va el loop:
<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>
// Etc..</pre></td></tr></table></div>

<p>Si queremos que se <strong>muestre para cada artículo una taxonomía concreta y los enlaces de las etiquetas relacionadas</strong> (por ejemplo, Autor: <u>Pink Floyd</u> donde Pink Floyd es un enlace)  utilizaríamos este código en el sitio donde queremos que salgan los enlaces de las etiquetas separadas con comas dentro del loop:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_the_term_list<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: #0000ff;">'autor'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Autor: '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Los tres últimos parámetros le indican a Wordpress qué escribir antes de los enlaces de las etiquetas, entre cada enlace y tras cada enlace.</p>
<p><strong>Condicionales que podemos usar con las taxonomías:</strong><br />
 is_tax(), is_tax(&#8216;nombre-de-la-taxonomia&#8217;), is_tax(array(&#8216;nombre1&#8242;,&#8217;nombre2&#8242;,&#8217;nombre3&#8242;)) </p>
<p>Como veis el uso de las taxonomías es muy sencillo y nos puede permitir mejorar el uso de Wordpress para crear webs de mayor complejidad. Gracias a la posibilidad de crear nuevas plantillas y sabiendo que podemos acceder a una taxonomía en concreto a través de una url amigable podemos crear menús y submenús con facilidad en los que accedamos a páginas concretas para cada taxonomía, por ejemplo. </p>
<h3>Taxonomías en páginas</h3>
<p>En el ejemplo anterior creábamos taxonomías para su uso en entradas (posts). Ahora veremos cómo crearlas en las <em>páginas</em>.<br />
Fuente: <a href="http://justintadlock.com/archives/2009/11/09/excerpts-and-taxonomies-for-pages-in-wordpress-2-9" title="Ir al artículo">http://justintadlock.com/archives/2009/11/09/excerpts-and-taxonomies-for-pages-in-wordpress-2-9</a><br />
Hay que recordar que en Wordpress 2.9 las Taxonomías no admiten jerarquización, como las categorías.<br />
Supongamos que creamos una Taxonomía para páginas llamada &#8220;people&#8221;:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">register_taxonomy<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'people'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'page'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'hierarchical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'People'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'query_var'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rewrite'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
add_action<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'admin_menu'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'my_page_taxonomy_meta_boxes'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> my_page_taxonomy_meta_boxes<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span> get_object_taxonomies<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'page'</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tax_name</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: #339933;">!</span>is_taxonomy_hierarchical<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$tax_name</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$tax</span> <span style="color: #339933;">=</span> get_taxonomy<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$tax_name</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			add_meta_box<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;tagsdiv-<span style="color: #006699; font-weight: bold;">{$tax_name}</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$tax</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">label</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'post_tags_meta_box'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'page'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'side'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'core'</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;">&#125;</span></pre></td></tr></table></div>

<div id="crp_related"><h3>Artículos relacionados:</h3><ul><li><a href="http://www.emenia.es/funciones-utiles-para-functions-php-en-wordpress/" rel="bookmark" class="crp_title">Funciones útiles para functions.php en Wordpress</a></li><li><a href="http://www.emenia.es/lista-productos-wordpress-3/" rel="bookmark" class="crp_title">Crear una lista de productos con Wordpress 3.0 usando Entradas personalizadas, campos personalizados y taxonomías</a></li><li><a href="http://www.emenia.es/la-funcion-body_class-en-wordpress/" rel="bookmark" class="crp_title">Clases dinámicas en body utilizando la función body_class() de Wordpress</a></li><li><a href="http://www.emenia.es/automatiza-el-ano-del-copyright-en-tu-web/" rel="bookmark" class="crp_title">Automatiza el año del copyright en tu web</a></li><li><a href="http://www.emenia.es/crea-tu-propia-red-social-con-wordpress-y-buddypress-introduccion/" rel="bookmark" class="crp_title">Crea tu propia red social con Wordpress y BuddyPress &#8211; Introducción</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emenia.es/taxonomias-en-wordpress/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Cómo incrementar la seguridad de una web creada con Wordpress</title>
		<link>http://www.emenia.es/como-incrementar-la-seguridad-de-una-web-creada-con-wordpress/</link>
		<comments>http://www.emenia.es/como-incrementar-la-seguridad-de-una-web-creada-con-wordpress/#comments</comments>
		<pubDate>Sun, 20 Dec 2009 10:28:06 +0000</pubDate>
		<dc:creator>Juan Diaz-Bustamante</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://emenia.es/?p=241</guid>
		<description><![CDATA[Es necesario tomar una serie de precauciones básicas para proteger nuestra instalación de Wordpress frente a usuarios malintencionados.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.emenia.es%2Fcomo-incrementar-la-seguridad-de-una-web-creada-con-wordpress%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.emenia.es%2Fcomo-incrementar-la-seguridad-de-una-web-creada-con-wordpress%2F&amp;source=JuanDBB_Emenia&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Dado el gran éxito de Wordpress son cada vez más altas las preocupaciones de sus usuarios por estar al día de todos los consejos relativos a la seguridad de su web. No es raro encontrar usuarios a los que les han hackeado su web, les han instalado un virus que borra toda la base de datos, tienen cuentas de administradores fantasmas o de repente generan miles de comentarios con enlaces a material adulto o de venta de viagra. Al ser tan popular Wordpress los ataques se disparan. Puedes pensar que esto no te va a pasar a tí, pero <strong>si no tomas las medidas necesarias de precaución aumentarás la probabilidad de que te ocurra</strong>.</p>
<p>Para evitar estos problemas o, al menos, para ponérselo lo más difícil posible a cualquier hacker o a cualquier robot que ande por la red buscando instalaciones de Wordpress desprevenidas lo mejor es seguir unas <strong>recetas básicas de seguridad</strong> antes, durante y después de la instalación de Wordpress.</p>
<h3>Antes de la instalación</h3>
<p>a) <strong>Muchas empresas de alojamiento ofrecen la posibilidad de instalar Wordpress de manera automática mediante Fantástico</strong>. Aunque es una opción realmente cómoda, tiene un inconveniente: No nos permite configurar a nuestro gusto la instalación de Wordpress, especialmente en cuanto al prefijo de las tablas en la base de datos, ya que se utilizará <strong><em>wp_</em></strong>, que es el que utiliza el programa de instalación por defecto. Si podéis, haced una instalación manual. Si preferís usar Fantástico recordad cambiar más adelante el prefijo de las tablas de la base de datos (veréis más adelante cómo hacerlo)</p>
<p>b) <strong>Antes de instalar Wordpress hemos de decidir dónde instalarlo</strong>. Lo podemos instalar en el directorio raíz de tu web, que sería lo normal. Pero también podemos instalarlo en una carpeta a la que le podemos dar un nombre cualquiera, por ejemplo &#8220;comentarios&#8221; u otro que se nos ocurra (algunos autores recomiendan utilizar nombres absurdos y difíciles de imaginar). Si hemos elegido &#8220;comentarios&#8221;, y para que nuestra web no aparezca como en http://www.miweb.es/comentarios/, necesitaremos mover los archivos index.php y .htaccess desde dentro de la carpeta &#8220;comentarios&#8221; al directorio raíz. Después habría que cambiar dentro de index.php estas líneas:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./wp-blog-header.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>a estas:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./comentarios/wp-blog-header.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Una vez hayas instalado Wordpress entra en tu panel de administración (www.miweb.es/comentarios/wp-admin) y ve a Opciones/General y asegúrate de que la Dirección de Wordpress (URL) sea http://www.miweb.es/comentarios/ (o cualquiera que sea en tu caso) y que la Dirección del Blog (URL) sea http://www.miweb.es/</p>
<p>De esta manera se adquiere un plus extra de seguridad frente a bots escaneando la red buscando archivos de Wordpress. Además, como ventaja, se obtiene un directorio raíz más limpio.</p>
<h3>Durante la instalación</h3>
<p>Durante la instalación hay varios procedimientos que fortalecerán tu instalación de Wordpress:</p>
<p>a) En primer lugar es recomendable <strong>cambiar el prefijo de de las tablas de la base de datos</strong> antes de que esta se genere. Este prefijo  se cambia en el archivo wp-config.php. Por defecto aparece &#8220;wp_&#8221;. Cámbialo por cualquier otro prefijo. Por ejemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$table_prefix</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'wp57B458F_'</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Si ya hemos instalado Wordpress y queremos cambiar el prefijo a posteriori, hay plugins que lo hacen por nosotros: <a href="http://blogsecurity.net/wordpress/tool-130707" title="Ir al plugin">WP Prefix Table Changer</a>, <a href="http://www.seoegghead.com/software/wordpress-table-rename.seo" title="Ir al Plugin">WordPress Table Prefix Rename Plugin</a> o <a href="http://wordpress.org/extend/plugins/wp-security-scan/" title="Ir a la web del Plugin">Wp-Security Scan</a> (del que hablaremos también más adelante).</p>
<p>b) Igualmente, en wp-config.php puedes definir <strong>cuatro claves de seguridad</strong> que te ayudan a incrementar la seguridad de Wordpress. Estas claves se pueden crear manualmente o a través de <a href="http://api.wordpress.org/secret-key/1.1/" title="Generar las claves de manera automática">Wordpress.org</a>. Estas cuatro claves se asignan a diferentes cookies y se utilizan en diversos lugares para incrementar la seguridad de Wordpress. Estas claves son:<br />
    * AUTH_KEY<br />
    * SECURE_AUTH_KEY T<br />
    * LOGGED_IN_KEY<br />
    * NONCE_KEY<br />
Símplemente copia los valores que hayas obtenido de manera automática en el enlace anterior de Wordpress.org en cada línea correspondiente de tu wp-config.php, por ejemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'AUTH_KEY'</span><span style="color: #339933;">,</span>        <span style="color: #0000ff;">'+tmh1=-+IPI[w{e_a-}_iK{@f#=?O0x0r|kMQ@{2@p%RTy9c&amp;GyCd)KavDk} H;F'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SECURE_AUTH_KEY'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'d,QY(bCxGwtdn&gt;QR=Gyi]3cS0}$DEz-+`,+%j!R[F@wGci;9g$`9sx#dlyE&gt;H6W|'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'LOGGED_IN_KEY'</span><span style="color: #339933;">,</span>   <span style="color: #0000ff;">'2!N--t@ML1]Xb|x0~Y C%J 4Q]-+~yBl$,k9ZX&lt;&lt;RxoG*B$1_r(_RPPi0HiRdIyA'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'NONCE_KEY'</span><span style="color: #339933;">,</span>       <span style="color: #0000ff;">'_w~2=`[pZpyZFf:]W.A{=)yuafy}QkZ@+X$@&gt;DgQUD8}QRXg^z5*j!Z(x6|lr|KB'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3>Una vez instalado Wordpress</h3>
<p>a) C<strong>rear un archivo vacío index.html</strong> en aquellos directorios que no lo tengan, lo que permite que no se pueda listar el contenido del directorio. Como alternativa más sencilla podemos añadir esta línea en nuestro archivo .htaccess: <strong>Options -Indexes</strong></p>
<p>b) <strong>Utilizar acceso seguro</strong>. Si en tu solución de hosting tienes posibilidad de utilizar acceso vía SSL (Secure Socket Layer), aunque sea compartido, utilízalo. Para ello tendrás que activarlo en el archivo wp-config.php:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">define</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'FORCE_SSL_LOGIN'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>c) <strong>Cambiar el nombre del usuario.</strong> El usuario por defecto de la nueva instalación será &#8220;admin&#8221;. Dejar este usuario es dar facilidades a cualquiera malintencionado. Hay dos opciones: o crear un nuevo usuario y borrar el usuario &#8220;admin&#8221; tal y como explico en un artículo anterior (<a href="http://www.emenia.es/primeros-pasos-tras-una-nueva-instalacion-de-wordpress/" title="Ir al artículo">Primeros pasos tras una nueva instalación de Wordpress</a>) o crear un nuevo usuario con funciones de administrador y al usuario admin cambiarle el rol a Suscriptor, para que no pueda hacer nada. </p>
<p>d) <strong>Mover el archivo wp-config.php:</strong> También explicado en mi artículo anterior. Este archivo es vital para proteger la seguridad de tu web. En él están datos vitales como los que permiten el acceso a tu base de datos. Wordpress permite mover este archivo a UNA carpeta superior dentro del alojamiento de la web. De esta manera podemos sacar este archivo fuera del acceso público sin ningún problema. Por ejemplo, si tenemos una estructura con varias carpetas en la que una es public_html, que es donde está la web, podemos sacar el archivo a la carpeta superior no accesible por el público general:</p>
<p><img src="http://www.emenia.es/wp-content/uploads/2009/09/wordpress_config1.jpg" alt="wordpress_config1" title="wordpress_config1" width="550" height="101" class="aligncenter size-full wp-image-85" /></p>
<p>e) <strong>Suprimir el mensaje de error en la entrada al administrador</strong>: Cuando vamos a acceder al administrador de Wordpress y nos equivocamos por ejemplo en la contraseña saldrá un mensaje que nos dirá que lo que está mal es la contraseña. Si no queremos dejar pistas podemos incluir esta línea en el archivo functions.php de nuestro tema:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'login_errors'</span><span style="color: #339933;">,</span><span style="color: #990000;">create_function</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'$a'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;return null;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>f) <strong>Utilizar una contraseña segura</strong>, que sea difícil de adivinar. Utiliza una contraseña larga, con mezcla de mayúsculas, minúsculas, números&#8230; Que sea una contraseña única que no hayas utilizado para ninguna otra cosa. Además es una buena idea cambiar de contraseña cada cierto tiempo.</p>
<p>g) <strong>Haz copias de seguridad de tu Base de Datos tan frecuentemente como sea necesario</strong>. Para hacer copias de seguridad manualmente vía phpMyadmin puedes seguir esta <a href="http://codex.wordpress.org/WordPress_Backups" title="Ir al paso a paso en Wordpress.org">guía paso a paso de Wordpress.org</a>. Hay también plugins que hacen la copia de seguridad por ti e incluso te la envían por email si así lo quieres, como <a href="http://wordpress.org/extend/plugins/wp-dbmanager/" title="Ir a la página del Plugin">WP-DBManager</a> o <a href="http://wordpress.org/extend/plugins/wp-db-backup/" title="Ir a la página del Plugin">WP-DB-Backup</a></p>
<p>h) Asegúrate de que el ordenador desde el que entras a tu panel de administración está libre de<strong> virus, spyware y cualquier programa malicioso</strong>.  Es importante que tengas en tu ordenador un buen antivirus puesto al día.</p>
<p>i) <strong>Mantén tu versión de Wordpress siempre actualizada a la última versión disponible</strong>. Hay ocasiones en la que incluso se crean nuevas versiones para hacer frente a agujeros de seguridad que se han descubierto en ese momento. Igualmente es importante <strong>mantener actualizados todos tus plugins</strong>.</p>
<p>j)<strong> Instala Plugins de Seguridad</strong>. Entre ellos destacan:<br />
- <a href="http://wordpress.org/extend/plugins/wp-security-scan/" title="Ir a la página del Plugin">WP Security Scan</a>, que comprueba tu instalación de Wordpress, busca áreas vulnerables y te propone acciones para corregirlas.<br />
- <a href="http://wordpress.org/extend/plugins/exploit-scanner/" title="Ir a la página del Plugin">WordPress Exploit Scanner</a>, que busca entre los ficheros de la web y entre las entradas y comentarios en las tablas de la base de datos cualquier cosa sospechosa.También busca entre los plugins activos ficheros con nombres sospechosos. No borra nada, símplemente te informa de los resultados de sus análisis.<br />
- <a href="http://wordpress.org/extend/plugins/limit-login-attempts/" title="Ir a la página del Plugin">Limit Login Attempts</a>, que limita el número de intentos posibles para entrar en el área de administración. Por defecto Wordpress permite un número ilimitado de intentos, lo cual es una facilidad añadida a cualquiera que quiera entrar mediante prueba-error.<br />
- <a href="http://wpantivirus.com/" title="Ir a la web del plugin">AntiVirus for Wordpress</a>,  que se centra en la detección de software malintencionado que pueda atacar nuestra instalación de Wordpress. Incluso te puede enviar notificaciones por email<br />
- <a href="http://akismet.com/" title="Ir a la web de Askimet">Askimet</a>, que viene instalado con Wordpress y sólo hay que activarlo, y que elimina todo el spam de los comentarios.</p>
<p>k) <strong>Seguridad vía .htaccess</strong>. Hay muchas opciones (ver <a href="http://blogsecurity.net/wordpress/article-210607" title="Ir al artículo">Hardening WordPress with htaccess</a>). Por ejemplo:</p>
<p>Si no podemos llevarnos el archivo wp-config.php como indicamos más arriba podemos protegerlo añadiendo en el archivo .htaccess que está en el directorio raiz lo siguiente para negar todos los accesos al archivo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># proteger wp-config.php
</span><span style="color: #339933;">&lt;</span>files wp<span style="color: #339933;">-</span>config<span style="color: #339933;">.</span>php<span style="color: #339933;">&gt;</span>
Order deny<span style="color: #339933;">,</span>allow
deny from all
<span style="color: #339933;">&lt;/</span>files<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Si queremos negar todos los accesos excepto los de una IP en particular al archivo wp-config-php:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># proteger wp-config.php
</span><span style="color: #339933;">&lt;</span>Files wp\<span style="color: #339933;">-</span>config\<span style="color: #339933;">.</span>php<span style="color: #339933;">&gt;</span>
Order Deny<span style="color: #339933;">,</span>Allow
Deny from all
Allow from 123<span style="color: #339933;">.</span>123<span style="color: #339933;">.</span>123
<span style="color: #339933;">&lt;/</span>Files<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Si tu IP es dinámica (como suele ser normalmente) y varía entre dos números (por ejemplo, entre 123.456.789.1 y 123.456.789.255) puedes poner:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># proteger wp-config.php
</span><span style="color: #339933;">&lt;</span>Files wp\<span style="color: #339933;">-</span>config\<span style="color: #339933;">.</span>php<span style="color: #339933;">&gt;</span>
Order Deny<span style="color: #339933;">,</span>Allow
Deny from all
Allow from 123<span style="color: #339933;">.</span>456<span style="color: #339933;">.</span>789
<span style="color: #339933;">&lt;/</span>Files<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>También podemos proteger el directorio wp-admin. La manera más sencilla de hacerlo es a través del archivo .htaccess situado dentro de dicho directorio (si no existiera puedes crearlo). Haríamos igual que antes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Proteger archivos de wp-admin
</span><span style="color: #339933;">&lt;</span>FilesMatch <span style="color: #0000ff;">&quot;*.*&quot;</span><span style="color: #339933;">&gt;</span>
Order Deny<span style="color: #339933;">,</span>Allow
Deny from all
Allow from 123<span style="color: #339933;">.</span>456<span style="color: #339933;">.</span>789
<span style="color: #339933;">&lt;/</span>FilesMatch<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p><strong>Debes tener cuidado al proteger el directorio wp-admin</strong>, ya que puede bloquear el acceso a algunos plugins o a algunas funcionalidades de Wordpress. Para evitar jaleos puedes instalar un plugin que haga esto por tí, como <a href="http://www.askapache.com/WordPress/htaccess-password-protect.html" title="Ir al plugin">AskApache Password Protection</a> o <a href="http://wordpress.org/extend/plugins/wp-adminprotection/" title="Ir al artículo">WP-Adminprotection</a></p>
<p>Además, podemos proteger toda una serie de archivos sensibles (.htaccess, .htpasswd, php.ini, scripts php, archivos flash .fla, archivos de photoshop .psd o archivos log) de igual manera:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Proteger archivos sensibles por tipo de fichero
</span><span style="color: #339933;">&lt;</span>FilesMatch <span style="color: #0000ff;">&quot;\.(htaccess|htpasswd|ini|phps|fla|psd|log)$&quot;</span><span style="color: #339933;">&gt;</span>
Order Deny<span style="color: #339933;">,</span>Allow
Deny from all
Allow from 123<span style="color: #339933;">.</span>456<span style="color: #339933;">.</span>789<span style="color: #339933;">.</span>0
<span style="color: #339933;">&lt;/</span>FilesMatch<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>l) Hay autores que aconsejan <strong>borrar el archivo wp-admin/install.php </strong>tras realizar la instalación de Wordpress ya que en alguna rara ocasión puede suceder que tras un error Wordpress piense que aún no está instalado y trate de ejecutar el archivo install.php<br />
Otra oción es sustituir el contenido del archivo por esto, mucho más útil, tal y como proponen en <a href="http://perishablepress.com/press/2009/05/05/important-security-fix-for-wordpress/" title="Ir al artículo">Important Security Fix for WordPress</a> (lo he dejado en inglés, como en el original):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #666666; font-style: italic;">// install.php replacement page: http://perishablepress.com/press/2009/05/05/important-security-fix-for-wordpress/ ?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HTTP/1.1 503 Service Temporarily Unavailable&quot;</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: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Status 503 Service Temporarily Unavailable&quot;</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: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Retry-After 3600&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// 60 minutes ?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;your@email.com&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Database Error&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;There is a problem with teh database!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt;
&lt;html xml:lang=&quot;en&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot; lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Error Establishing Database Connection&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;img src=&quot;images/wordpress-logo.png&quot; /&gt;
&lt;h1&gt;Error Establishing Database Connection&lt;/h1&gt;
&lt;p&gt;We are currently experiencing database issues. Please check back shortly. Thank you.&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre></td></tr></table></div>

<p>m) <strong>Dejar de mostrar la versión de Wordpress que tenemos instalada</strong>. Muchos temas de Wordpress la muestran, lo cual no deja de dar pistas a usuarios malintencionados. Para ello añadiríamos la siguiente línea al archivo functions.php de nuestro tema:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> remove_action<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'wp_head'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'wp_generator'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>n) <strong>Evitar que otras webs utilicen imágenes u otro contenido de tu web (lo que se suele llamar hotlinks)</strong>. Me ha ocurrido en ocasiones que otras webs han utilizado imágenes, iconos, etc.. de webs mías simplemente enlazándolas con lo cual utilizan ancho de banda mío. Para evitarlo lo podemos hacer vía el archivo .htaccess:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># Protección frente a hotlinks de archivos .jpg, .jpeg, .jpe, .gif, .png
</span><span style="color: #339933;">&lt;</span>IfModule mod_rewrite<span style="color: #339933;">.</span>c<span style="color: #339933;">&gt;</span>
RewriteEngine on
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_REFERER<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!</span>^$
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_FILENAME<span style="color: #009900;">&#125;</span> <span style="color: #339933;">-</span>f
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>REQUEST_FILENAME<span style="color: #009900;">&#125;</span> \<span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span>gif<span style="color: #339933;">|</span>jpe?g?<span style="color: #339933;">|</span>png<span style="color: #009900;">&#41;</span>$ <span style="color: #009900;">&#91;</span>NC<span style="color: #009900;">&#93;</span>
RewriteCond <span style="color: #339933;">%</span><span style="color: #009900;">&#123;</span>HTTP_REFERER<span style="color: #009900;">&#125;</span> <span style="color: #339933;">!</span>^https?<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//([^.]+\.)?domain\. [NC]</span>
RewriteRule \<span style="color: #339933;">.</span><span style="color: #009900;">&#40;</span>gif<span style="color: #339933;">|</span>jpe?g?<span style="color: #339933;">|</span>png<span style="color: #009900;">&#41;</span>$ <span style="color: #339933;">-</span> <span style="color: #009900;">&#91;</span>F<span style="color: #339933;">,</span>NC<span style="color: #339933;">,</span>L<span style="color: #009900;">&#93;</span>
<span style="color: #339933;">&lt;/</span>ifModule<span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<p>Podemos encontrar más consejos sobre este particular en <a href="http://perishablepress.com/press/2007/11/21/creating-the-ultimate-htaccess-anti-hotlinking-strategy/" title="Ir al artículo">Creating the Ultimate htaccess Anti-Hotlinking Strategy</a>.</p>
<p>o) En septiembre del 2009 hubo un ataque generalizado a muchas instalaciones de Wordpress, que fueron infectadas con código malicioso. Recientemente Jeff Starr de <a href="http://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/" title="Ir al artículo">Perishable Press</a> ha propuesto una solución que protege igualmente de ataques futuros. Simplemente hay que crear un fichero php con este código y guardarlo en la carpeta plugins. Al activarlo desde el panel de administración nos protegerá silenciosamente detectando solicitudes con cadenas demasiado grandes (más de 255 caracteres) así como la presencia de  “eval(” o “base64” en el URI solicitado.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #666666; font-style: italic;">/* Plugin Name: Block Bad Queries */</span>
&nbsp;
    <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;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> <span style="color: #cc66cc;">255</span> <span style="color: #339933;">||</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;">&quot;eval(&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</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;">&quot;base64&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #339933;">@</span><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;HTTP/1.1 414 Request-URI Too Long&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">@</span><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Status: 414 Request-URI Too Long&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">@</span><span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Connection: Close&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #339933;">@</span><span style="color: #990000;">exit</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Hay muchas más opciones recomendables, aunque con las anteriores se conseguiría un nivel de protección muy alto. Es conveniente estar suscrito a blogs de Wordpress donde estar al día de las novedades que vayan surgiendo sobre el particular, como por ejemplo el blog en Español <a href="http://ayudawordpress.com/">Ayuda Wordpress</a>.</p>
<div id="crp_related"><h3>Artículos relacionados:</h3><ul><li><a href="http://www.emenia.es/primeros-pasos-tras-una-nueva-instalacion-de-wordpress/" rel="bookmark" class="crp_title">Primeros pasos tras una nueva instalación de Wordpress</a></li><li><a href="http://www.emenia.es/nuevo-en-wordpress-2-9-miniaturas-de-entrada-post-thumbnails/" rel="bookmark" class="crp_title">Nuevo en Wordpress 2.9: Miniaturas de Entrada (Post Thumbnails)</a></li><li><a href="http://www.emenia.es/barra-lateral-diferente-para-cada-pagina-en-wordpress/" rel="bookmark" class="crp_title">Barra Lateral diferente para cada página en Wordpress</a></li><li><a href="http://www.emenia.es/lista-desplegable-y-plegable-con-jquery/" rel="bookmark" class="crp_title">Lista desplegable y plegable con jQuery</a></li><li><a href="http://www.emenia.es/funciones-utiles-para-functions-php-en-wordpress/" rel="bookmark" class="crp_title">Funciones útiles para functions.php en Wordpress</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emenia.es/como-incrementar-la-seguridad-de-una-web-creada-con-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cómo separar los artículos por categorías en Wordpress</title>
		<link>http://www.emenia.es/como-separar-los-articulos-por-categorias-en-wordpress/</link>
		<comments>http://www.emenia.es/como-separar-los-articulos-por-categorias-en-wordpress/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 11:03:45 +0000</pubDate>
		<dc:creator>Juan Diaz-Bustamante</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://emenia.es/?p=186</guid>
		<description><![CDATA[Recuerdo que cuando veía periódicos o revistas creados con Wordpress me preguntaba ¿Cómo crearán un menú con los distintos tipos de noticias? y sobre todo ¿Cómo lo harán para tener en una misma página las noticias separadas en función de su tema (deportes, economía, política, etc...) si sólo hay un loop? ]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.emenia.es%2Fcomo-separar-los-articulos-por-categorias-en-wordpress%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.emenia.es%2Fcomo-separar-los-articulos-por-categorias-en-wordpress%2F&amp;source=JuanDBB_Emenia&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Recuerdo que cuando veía periódicos o revistas creados con Wordpress me preguntaba ¿Cómo crearán un menú con los distintos tipos de noticias? y sobre todo ¿Cómo lo harán para tener en una misma página las noticias separadas en función de su tema (deportes, economía, política, etc&#8230;) si sólo hay un loop? </p>
<p>Cuando me puse a investigarlo vi que era muy sencillo. Vamos a verlo en detalle:</p>
<h3>Cómo crear un navegador con categorías</h3>
<p>Tendríamos un menú principal de este tipo, por ejemplo:</p>
<p><img src="http://emenia.es/wp-content/uploads/2009/10/CD_portada.jpg" alt="CD_portada" title="CD_portada" width="600" height="54" class="aligncenter size-full wp-image-187" /></p>
<p>de tal manera que al hacer click en una de las opciones vayamos a una página que incluya solamente las noticias de la categoría escogida (por ejemplo, Sociedad).</p>
<p>Lo primero que tendríamos que hacer es crear nuestras categorías en el Administrador de Wordpress. Si abrimos el administrador, para escribir un nuevo artículo haríamos click en <strong><em>Entradas</em></strong> (menú de la izquierda, arriba) <strong>y luego en <em>Añadir</em></strong>. Estaríamos entonces en una ventana que se llama <strong><em>Agregar Nueva Entrada</em></strong>. Aquí escribimos nuestro artículo. Como veis en la siguiente imagen, a la derecha tenéis un cuadro que se llama Categorías. Aquí asignáis una (o varias) categorías a vuestro artículo. Si no existiese la categoría correspondiente, la creáis.</p>
<p><img src="http://emenia.es/wp-content/uploads/2009/10/categorias.png" alt="categorias" title="categorias" width="550" height="348" class="aligncenter size-full wp-image-188" /></p>
<p>También se pueden crear y editar categorías en la opción del menú Entradas/Categorías.</p>
<p>Por lo tanto, al crear un nuevo artículo seleccionamos la categoría en la que queramos encuadrarlo (Nacional, Internacional, Deportes, Política, Sucesos o cualquier otra categoría que hayamos creado).</p>
<p>El navegador de nuestra web, que normalmente suele estar en header.php, suele estar definido de esta forma:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;title_li='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Así crearemos una lista con tódas las páginas creadas. Pero si lo que queremos son categorías y no páginas lo haríamos de esta forma:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_list_categories<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;title_li='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Pero si queremos mezclar páginas con categorías (por ejemplo la página de Portada seguida de las categorías):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'include=3&amp;title_li='</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> wp_list_categories<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'&amp;title_li='</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Aquí incluimos primero la página que tiene el ID 3 (suponemos que la de Portada. En el administrador de Wordpress eligiríamos esta página como la de apertura del blog), y luego las categorías.</p>
<p>Con esto tendríamos ya nuestro navegador, al que le daríamos los estilos que más nos convengan. </p>
<p>Pero, <strong>¿qué hará Wordpress si hacemos click en el enlace Deportes (por ejemplo)?</strong> Buscará en nuestro tema la página correspondiente a esa Categoría <strong>donde sólo saldrán las entradas que tengan esa Categoría</strong>.</p>
<p>Cada Categoría tiene un ID (o número que la identifica). Si en el menú de la izquierda del Administrador vamos a <strong><em>Entradas/Categorías</em></strong> veremos todas nuestras categorías. Al situar el ratón sobre una categoría se muestra abajo en el navegador el URL de esa categoría con un número al final. <strong>Ese es su ID</strong>. Ahora supongamos que la categoría &#8220;Deportes&#8221; tiene un ID=3. Al hacer click sobre &#8220;Deportes&#8221; en el navegador que hemos creado, Wordpress va a buscar la página <strong>category-3.php</strong> en la carpeta de nuestro tema. </p>
<p>Es decir, siempre va a buscar primero <strong>category-ID.php</strong>, donde ID es el ID de la categoría correspondiente.  Si no existe el category-ID.php buscará el archivo category.php, y si este no existe buscará archive.php y si (por último) este no existe buscará index.php</p>
<p>Por lo tanto, si quieres hacer que una Categoría cuyo ID=3 sea diferente a las páginas de otras categorías necesitarás crear un category-3.php</p>
<p>Para crearlo es aconsejable copiar el archivo category.php y cambiarlo de nombre para empezar a trabajar desde los contenidos de category.php adaptándolos con los cambios que queramos realizar.</p>
<p><strong>Vamos ahora con nuestro segunda pregunta</strong>, cómo conseguir que en una misma página (por ejemplo la portada de un periódico) tengamos distintas noticias en lugares distintos del periódico agrupadas en función de su categoría.</p>
<h3>Distintos loops en la misma página diferenciados por categorías</h3>
<p>Para crear una <strong>portada</strong> que incluya noticias de todas las categorías pero <strong>ordenadas según su categoría</strong> (por ejemplo, por un lado las de Actualidad, por otro las de Sociedad, etc..) no nos vale con el &#8220;loop&#8221; único que tenemos en Wordpress por defecto. Necesitaremos un &#8220;loop&#8221; por cada categoría. Como en este ejemplo, de un periódico nacional:</p>
<p><img src="http://emenia.es/wp-content/uploads/2009/10/periodico.jpg" alt="periodico" title="periodico" width="474" height="826" class="aligncenter size-full wp-image-189" /></p>
<p>Como vemos las noticias se agrupan en función de su categoría (en este caso Internacional, España, Economía y Cultura).</p>
<p>Si no queremos tener todas las noticias juntas y queremos agruparlas según su categoría y darles un estilo y ubicación diferente en función de dicha categoría necesitaremos crear un &#8220;loop&#8221; para cada categoría. Esto se consigue sustituyendo el &#8220;loop&#8221; habitual de Wordpress&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;div <span style="color: #000000; font-weight: bold;">&lt;?php</span> post_class<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> id=&quot;post-<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
    &lt;h2&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; rel=&quot;bookmark&quot; title=&quot;Enlace a <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title_attribute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h2&gt;
	&lt;small&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'F jS, Y'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;!-- by <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_author<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> --&gt;&lt;/small&gt;
          &lt;div class=&quot;entry&quot;&gt;
	    <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Leer el resto de esta noticia &amp;raquo;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	  &lt;/div&gt;
	&lt;p class=&quot;postmetadata&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_tags<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Tags: '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">', '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'&lt;br /&gt;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>Publicado en <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">', '</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> | <span style="color: #000000; font-weight: bold;">&lt;?php</span> edit_post_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Editar'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' | '</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> comments_popup_link<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No hay comentarios &amp;#187;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1 Comentario &amp;#187;'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'% Comentarios &amp;#187;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/p&gt;
  &lt;/div&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>&#8230; por tantos &#8220;loops&#8221; como sea necesario, y<strong> esto se consigue gracias a WP_Query</strong>.</p>
<p>Por ejemplo, si queremos una sección que sólo muestre la categoría &#8220;Deportes&#8221;, necesitarás haber creado esa categoría previamente en Wordpress así como diversas noticias que pertenezcan a esa categoría. </p>
<p>El código ahora (en vez del anteriormente visto) será ahora:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
  <span style="color: #000088;">$deportes</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$deportes</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category_name=Deportes&amp;showposts=5'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$deportes</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;">$deportes</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: #000000; font-weight: bold;">?&gt;</span>
    &lt;div class=&quot;post&quot;&gt;
      &lt;h4&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;/h4&gt;
      &lt;div class=&quot;entry&quot;&gt;
        <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Leer el resto de esta noticia &amp;raquo;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
      &lt;/div&gt;
    &lt;/div&gt;
  <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>$deportes es la variable que utilizamos aquí para la sección de Deportes creando una nueva instancia de WP_Query(). Luego aplicamos los parámetros que necesitemos, en este caso que se muestren sólo las entradas cuyo nombre de categoría sea Deportes y que se muestren 5 entradas. El resto es una versión corta del &#8220;loop&#8221; de wordpress. </p>
<p>Si queremos utilizar el ID de la categoría en vez de su nombre cambiaríamos esta línea (suponiendo que Deportes sea la categoría 3):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$deportes</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cat=3&amp;showposts=5'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>¿Que además de Deportes queremos Nacional, Internacional, Economía, etc&#8230;? Pues sólo hay que crear un bloque de código como el anterior para cada categoría. ¡Así de sencillo!</p>
<h3>Más lecturas recomendadas</h3>
<p><a href="http://wefunction.com/2008/12/taking-wordpress-one-step-further/">Function</a>, habla un poco sobre los &#8220;loops&#8221; personalizados.<br />
<a href="http://net.tutsplus.com/working-with-cmss/build-a-newspaper-theme-with-wp_query-and-the-960-css-framework/">NetPlus</a> tiene un artículo completo sobre como crear un periódico con Wordpress.<br />
<a href="http://codex.wordpress.org/Function_Reference/WP_Query">WP_Query</a> en la documentación de Wordpress.<br />
<a href="http://codex.wordpress.org/The_Loop">Sobre el Loop</a> y WP_Query en el manual de referencia de Wordpress.<br />
<a href="http://wpengineer.com/quick-tipps-for-wordpress-query/">WPEngineer.com</a> muestra varios trucos para WP_Query</p>
<div id="crp_related"><h3>Artículos relacionados:</h3><ul><li><a href="http://www.emenia.es/funciones-utiles-para-functions-php-en-wordpress/" rel="bookmark" class="crp_title">Funciones útiles para functions.php en Wordpress</a></li><li><a href="http://www.emenia.es/taxonomias-en-wordpress/" rel="bookmark" class="crp_title">Taxonomías en Wordpress</a></li><li><a href="http://www.emenia.es/os-presento-codigoytrucos-com/" rel="bookmark" class="crp_title">Os presento CodigoyTrucos.com</a></li><li><a href="http://www.emenia.es/recopilacion-de-45-trucos-para-wordpress/" rel="bookmark" class="crp_title">Recopilación de 45 trucos para Wordpress</a></li><li><a href="http://www.emenia.es/como-limitar-el-numero-de-palabras-en-the_content-o-the_excerpt-en-wordpress/" rel="bookmark" class="crp_title">Cómo limitar el número de palabras en the_content o the_excerpt en Wordpress</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emenia.es/como-separar-los-articulos-por-categorias-en-wordpress/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Recopilación de 45 trucos para Wordpress</title>
		<link>http://www.emenia.es/recopilacion-de-45-trucos-para-wordpress/</link>
		<comments>http://www.emenia.es/recopilacion-de-45-trucos-para-wordpress/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 09:50:42 +0000</pubDate>
		<dc:creator>Juan Diaz-Bustamante</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://emenia.es/?p=150</guid>
		<description><![CDATA[Recopilación de 45 trucos de Wordpress para mejorar la funcionalidad de tus webs y blogs]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.emenia.es%2Frecopilacion-de-45-trucos-para-wordpress%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.emenia.es%2Frecopilacion-de-45-trucos-para-wordpress%2F&amp;source=JuanDBB_Emenia&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Esta es una recopilación de los mejores trucos que he ido recopilando para Wordpress de diversas fuentes (las principales están al pie del artículo). Muchos de ellos los utilizo con frecuencia.</p>
<h3 style="color:#F47474; font-style:italic">Sobre Artículos</h3>
<h3>Mostrar los artículos más recientes</h3>
<p>Este código muestra los cinco artículos más recientes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'showposts=5'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">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;li&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/li&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ul&gt;</pre></td></tr></table></div>

<h3>Mostrar los artículos o páginas recientemente actualizadas</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$today</span> <span style="color: #339933;">=</span> current_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mysql'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$howMany</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Número de entradas que quieres mostrar</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$recentposts</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT ID, post_title FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span> WHERE post_status = 'publish' AND post_modified_gmt &lt; '<span style="color: #006699; font-weight: bold;">$today</span>' ORDER BY post_modified_gmt DESC LIMIT <span style="color: #006699; font-weight: bold;">$howMany</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;h2&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> _e<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Ultimas actualizaciones&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/h2&gt;
&lt;ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$recentposts</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$post</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: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span> <span style="color: #339933;">=</span> <span style="color: #990000;">sprintf</span><span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Post #%s'</span><span style="color: #009900;">&#41;</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: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;li&gt;&lt;a href='&quot;</span><span style="color: #339933;">.</span>get_permalink<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: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;'&gt;&quot;</span><span style="color: #339933;">;</span>
the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;/a&gt;&lt;/li&gt;'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Mostras los artículos &#8220;pegados&#8221; (sticky) más recientes</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">/* Obtener todos los artículos sticky */</span>
<span style="color: #000088;">$sticky</span> <span style="color: #339933;">=</span> get_option<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'sticky_posts'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Ordenar los artículos sticky con los más nuevos arriba */</span>
<span style="color: #990000;">rsort</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sticky</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/* Obtener los dos artículos sticky más nuevos (cambia el 2 por el número que quieras) */</span>
<span style="color: #000088;">$sticky</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_slice</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$sticky</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</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: #666666; font-style: italic;">/* Hacer un query_posts con los artículos sticky */</span>
query_posts<span style="color: #009900;">&#40;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'post__in'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$sticky</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'caller_get_posts'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Mostrar los artículos más populares en función del número de comentarios</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT comment_count,ID,post_title FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span> ORDER BY comment_count DESC LIMIT 0 , 5&quot;</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;">$result</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
setup_postdata<span style="color: #009900;">&#40;</span><span style="color: #000088;">$post</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$postid</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: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$commentcount</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_count</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$commentcount</span> <span style="color: #339933;">!=</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;li&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$postid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$title</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$title</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt; {<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$commentcount</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>}&lt;/li&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>
&lt;/ul&gt;</pre></td></tr></table></div>

<h3>Añadir enlaces de traducción de los artículos a otros idiomas</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;a href=&quot;http://translate.google.com/translate?u=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</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: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;amp;langpair=es%7Cen&quot; class=&quot;translate&quot; title=&quot;Translate this page using Google Translate&quot; rel=&quot;nofollow&quot;&gt;Translate this page into English&lt;/a&gt;</pre></td></tr></table></div>

<p>Para otros idiomas simplemente sustituye el <em>en</em> de <em>langpair=es%7Cen</em> por <em>de</em> (Alemán), <em>fr</em> (Frances), <em>it</em> (Italiano), <em>pt</em> (Portugués), <em>ar</em> (Arabe), <em>ja</em> (Japonés, ko (Koreano), etc&#8230;</p>
<h3>Incluir código PHP dentro de los artículos (desde el administrador)</h3>
<p>Al escribir código desde el editor del administrador dentro de un artículo Wordpress transforma los códigos de inicio y final de php en caracteres de texto, por lo tanto si escribes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?</span> php query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'p=5'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>no ocurrirá nada. Hay que sustituirlo por sus códigos equivalentes:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>? php query_posts<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span><span style="color: #666666; font-style: italic;">#39;p=5&amp;#39;); ?&amp;gt;</span></pre></td></tr></table></div>

<h3>Lista de futuros artículos</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'showposts=10&amp;post_status=future'</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;h2&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;/h2&gt;  
   &lt;span class=&quot;datetime&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'j. F Y'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/span&gt;&lt;/p&gt;  
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span>  
<span style="color: #b1b100;">else</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;p&gt;No está programado ningún artículo&lt;/p&gt;  
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Mostrar otros artículos del mismo autor y de la misma categoría</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">post<span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_author</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tempQuery</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$currentId</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>
&nbsp;
<span style="color: #666666; font-style: italic;">// Otros artículos del mismo autor</span>
  <span style="color: #000088;">$newQuery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;posts_per_page=5&amp;author=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$authorPosts</span><span style="color: #339933;">;</span>
  query_posts<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$newQuery</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$authorPosts</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</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: #009900;">&#123;</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: #009900;">&#123;</span>
  <span style="color: #000088;">$count</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;">$count</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">4</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$currentId</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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$count</span><span style="color: #339933;">++;</span>
  <span style="color: #000088;">$authorPosts</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'
&lt;li&gt;&lt;a href=&quot;%27%20.%20get_permalink%28%29%20.%20%27&quot;&gt;'</span> <span style="color: #339933;">.</span> the_title<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;&lt;/li&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Otros artículos de la misma categoría</span>
  <span style="color: #000088;">$catlist</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #b1b100;">forEach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$cats</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$c</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: #000088;">$catlist</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000088;">$catlist</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$catlist</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$c</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">cat_ID</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$newQuery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;posts_per_page=5&amp;cat=&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$catlist</span><span style="color: #339933;">;</span>
  query_posts<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$newQuery</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$categoryPosts</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</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: #009900;">&#123;</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: #009900;">&#123;</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;">$count</span><span style="color: #339933;">&lt;</span><span style="color: #cc66cc;">4</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$currentId</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: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$count</span><span style="color: #339933;">++;</span>
  <span style="color: #000088;">$categoryPosts</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'
&lt;li&gt;&lt;a href=&quot;%27%20.%20get_permalink%28%29%20.%20%27&quot;&gt;'</span> <span style="color: #339933;">.</span> the_title<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/a&gt;&lt;/li&gt;
&nbsp;
'</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000088;">$wp_query</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tempQuery</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Mostrar un submenú de páginas en la barra lateral</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><span style="color: #000088;">$children</span> <span style="color: #339933;">=</span> wp_list_pages<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'title_li=&amp;child_of='</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: #0000ff;">'&amp;echo=0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>if <span style="color: #009900;">&#40;</span><span style="color: #000088;">$children</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;ul&gt; <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$children</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3 style="color:#F47474; font-style:italic">Sobre Comentarios</h3>
<h3>Mostrar los últimos comentarios</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_date_gmt, comment_approved,
comment_type,comment_author_url,
SUBSTRING(comment_content,1,30) AS com_excerpt
FROM <span style="color: #006699; font-weight: bold;">$wpdb-&gt;comments</span>
LEFT OUTER JOIN <span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span> ON (<span style="color: #006699; font-weight: bold;">$wpdb-&gt;comments</span>.comment_post_ID =
<span style="color: #006699; font-weight: bold;">$wpdb-&gt;posts</span>.ID)
WHERE comment_approved = '1' AND comment_type = '' AND
post_password = ''
ORDER BY comment_date_gmt DESC
LIMIT 10&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$comments</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$pre_HTML</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&lt;ul&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&lt;li&gt;&quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_author</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;:&quot;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&lt;a href=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">.</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span>
<span style="color: #0000ff;">&quot;#comment-&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">comment_ID</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span> title=<span style="color: #000099; font-weight: bold;">\&quot;</span>en &quot;</span> <span style="color: #339933;">.</span>
<span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_title</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">com_excerpt</span><span style="color: #009900;">&#41;</span>
<span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&lt;/a&gt;&lt;/li&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&lt;/ul&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$output</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$post_HTML</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Reordenar los comentarios para que aparezcan primero los más recientes</h3>
<p>Busca esta línea en <em>comments.php</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$comments</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$comment</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Añade antes de ella esta otra línea:</p>

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

<h3>Dar un diseño diferente a los comentarios del autor del blog</h3>
<p>Fuente: <a href="http://www.techieblues.com/wordpress/how-to-highlight-author-comments-in-wordpress/">Highlight Author Comments in Wordpress</a></p>
<p>Abre tu hoja de estilos (normalmente style.css) y añade este código:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.authcomment</span> <span style="color: #00AA00;">&#123;</span>
<span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#B3FFCC</span> !important<span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<p>Solamente hemos cambiado el fondo del comentario. Aquí podrás dar el diseño que te parezca más oportuno.</p>
<p>Después ve al archivo comments.php y busca esta línea:</p>

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

<p>Y sustitúyela por:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;li class=”<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$comment</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">user_id</span><span style="color: #009900;">&#41;</span>
<span style="color: #000088;">$oddcomment</span> <span style="color: #339933;">=</span> “authcomment”<span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$oddcomment</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Ten en cuenta que el autor por defecto en Wordpress es &#8220;<em>admin</em>&#8221; por lo que el valor por defecto de  “user_id” es ‘1?, por lo que si has cambiado el administrador por defecto (muy recomendable) creando un nuevo usuario tendrás que cambiar el valor de “user_id” por el nuevo, que se puede encontrar facilmente en Usuarios -> Autores y Usuarios de tu Tablero de Wordpress pasando el ratón sobre el número de entradas. El URL será algo parecido a http://www.tudominio.com/wp-admin/edit.php?author=&#8221;user_id&#8221; </p>
<h3 style="color:#F47474; font-style:italic">Sobre Categorías</h3>
<h3>Mostrar una lista de categorías</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;h2&gt;Categories&lt;/h2&gt;
&lt;ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_list_cats<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sort_column=name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ul&gt;</pre></td></tr></table></div>

<h3>Eliminar ciertas categorías del Loop</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cat=-3'</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: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	&lt;h3&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; rel=&quot;bookmark&quot; title=&quot;Ir a <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title_attribute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/h3&gt;
	&lt;p&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'j'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> de <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'F'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> de <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_time<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y'</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> 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>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Mostrar las categorías en un menú desplegable</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;form action=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/&quot; method=&quot;get&quot;&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$select</span> <span style="color: #339933;">=</span> wp_dropdown_categories<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'show_option_none=Seleccionar categor&amp;iacute;a&amp;show_count=1&amp;orderby=name&amp;echo=0'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$select</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#&lt;select([^&gt;]*)&gt;#&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&lt;select<span style="color: #006699; font-weight: bold;">$1</span> onchange='return this.form.submit()'&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$select</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$select</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;noscript&gt;&lt;input type=&quot;submit&quot; value=&quot;Ver&quot; /&gt;&lt;/noscript&gt;
&lt;/form&gt;</pre></td></tr></table></div>

<h3 style="color:#F47474; font-style:italic">Relacionados con el Loop</h3>
<h3>Crea tus propios Loops utilizando WP_Query</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>  
<span style="color: #000088;">$myPosts</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: #009900;">&#41;</span><span style="color: #339933;">;</span>  
<span style="color: #000088;">$myPosts</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'showposts=5'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
<span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$myPosts</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;">$myPosts</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: #000000; font-weight: bold;">?&gt;</span>  
   the_title();  
   the_content();  
endwhile;  
?&gt;</pre></td></tr></table></div>

<h3>Crear un loop con la primera imagen de cada artículo</h3>
<p>Primero hay que crear esta función y añadirla en functions.php de nuestro tema:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> catch_that_image<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;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">,</span> <span style="color: #000088;">$posts</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$first_img</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&lt;img.+src=[\'&quot;]([^\'&quot;]+)[\'&quot;].*&gt;/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$first_img</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$matches</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$first_img</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;">// Define una imagen por defecto</span>
    <span style="color: #000088;">$first_img</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/images/default.jpg&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$first_img</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Ahora ya podemos obtener las imágenes y crear el loop:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #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;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; class=&quot;img-loop&quot;&gt;
        &lt;img src=&quot;http://media1.smashingmagazine.com/wp-content/uploads/images/wordpress-loop-hacks/<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> catch_that_image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; alt=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
        &lt;/a&gt;
    endwhile;
endif;
?&gt;</pre></td></tr></table></div>

<h3 style="color:#F47474; font-style:italic">Relacionados con  el Archivo</h3>
<h3>Mostrar los archivos por meses</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;h2&gt;Archivos&lt;/h2&gt;
&lt;ul&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_get_archives<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type=monthly'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ul&gt;</pre></td></tr></table></div>

<h3>Mostrar los archivos en un menú desplegable</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;select name=\&quot;archive-dropdown\&quot; onChange='document.location.href=this.options[this.selectedIndex].value;'&gt;
&lt;option value=\&quot;\&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> attribute_escape<span style="color: #009900;">&#40;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Seleccionar Mes'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/option&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_get_archives<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type=monthly&amp;format=option&amp;show_post_count=1'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> &lt;/select&gt;</pre></td></tr></table></div>

<h3 style="color:#F47474; font-style:italic">Relacionados con  los Avatares</h3>
<h3>Mostrar Gravatars</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span>’get_avatar’<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">echo</span> get_avatar<span style="color: #009900;">&#40;</span><span style="color: #000088;">$comment</span><span style="color: #339933;">,</span> ‘<span style="color: #cc66cc;">50</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></td></tr></table></div>

<h3>Cambiar el tamaño del avatar</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_list_comments<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'avatar_size=80'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3 style="color:#F47474; font-style:italic">Relacionados con  las Etiquetas</h3>
<h3>Mostrar las etiquetas</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> the_tags<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Mostrar una nube de etiquetas</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_tag_cloud<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'smallest=8&amp;largest=36&amp;'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Mostrar artículos relacionados sin plugin en base a etiquetas</h3>
<p>Abre <em>single.php</em> e incluye este código dentro del <em>loop</em>. Obtiene la primera etiqueta y muestra los últimos 5 artículos con la misma etiqueta:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #339933;">/</span>para usar dentro del loop<span style="color: #339933;">,</span> muestra los títulos de <span style="color: #cc66cc;">5</span> artículos relacionados con la primera etiqueta del artículo actual
<span style="color: #000088;">$tags</span> <span style="color: #339933;">=</span> wp_get_post_tags<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: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Art&amp;iacute;culos relacionados'</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$first_tag</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">term_id</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$args</span><span style="color: #339933;">=</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'tag__in'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$first_tag</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'post__not_in'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</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: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'showposts'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'caller_get_posts'</span><span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">1</span>
   <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <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: #000088;">$args</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;">$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: #009900;">&#123;</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: #000000; font-weight: bold;">?&gt;</span>
      &lt;p&gt;&lt;a href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; rel=&quot;bookmark&quot; title=&quot;Enlace a <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title_attribute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/a&gt;&lt;/p&gt;
      <span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Obtener etiquetas relacionadas con una categoría</h3>
<p>Obtenido de <a href="http://www.wprecipes.com/wordpress-trick-function-to-get-tags-related-to-category">WpRecipes</a>. Se incluye esta función en functions.php:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_category_tags<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</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;">$wpdb</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$tags</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">get_results</span>
	<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;
		SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, null as tag_link
		FROM
			wp_posts as p1
			LEFT JOIN wp_term_relationships as r1 ON p1.ID = r1.object_ID
			LEFT JOIN wp_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
			LEFT JOIN wp_terms as terms1 ON t1.term_id = terms1.term_id,
&nbsp;
			wp_posts as p2
			LEFT JOIN wp_term_relationships as r2 ON p2.ID = r2.object_ID
			LEFT JOIN wp_term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
			LEFT JOIN wp_terms as terms2 ON t2.term_id = terms2.term_id
		WHERE
			t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.term_id IN (&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'categories'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;) AND
			t2.taxonomy = 'post_tag' AND p2.post_status = 'publish'
			AND p1.ID = p2.ID
		ORDER by tag_name
	&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$tags</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$tag</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$tags</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$count</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tag_link</span> <span style="color: #339933;">=</span> get_tag_link<span style="color: #009900;">&#40;</span><span style="color: #000088;">$tag</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tag_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$count</span><span style="color: #339933;">++;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$tags</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Entonces ya podemos llamar a la función en nuestro tema:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$args</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'categories'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'12,13,14'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tags</span> <span style="color: #339933;">=</span> get_category_tags<span style="color: #009900;">&#40;</span><span style="color: #000088;">$args</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3 style="color:#F47474; font-style:italic">Relacionados con  Imágenes</h3>
<h3>Obtener la primera imagen de cada artículo y ofrecerla en la página principal del blog como imagen del artículo</h3>
<p>Es una alternativa a los campos personalizados utilizados para este mismo uso.</p>
<p>Hay que añadir esta función al archivo functions.php de tu tema:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> catch_that_image<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;">global</span> <span style="color: #000088;">$post</span><span style="color: #339933;">,</span> <span style="color: #000088;">$posts</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$first_img</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">ob_start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #990000;">ob_end_clean</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/&lt;img.+src=[\'&quot;]([^\'&quot;]+)[\'&quot;].*&gt;/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post_content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000088;">$first_img</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$matches</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$first_img</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;">//Imagen por defecto</span>
    <span style="color: #000088;">$first_img</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;/images/default.jpg&quot;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$first_img</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>En la página principal de tu blog (index.php) incluye ahora una llamada a la función:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> catch_that_image<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Cambiar de forma automática el tamaño de las imágenes usando Timthumb</h3>
<p>Permite cambiar de manera automática el tamaño de las imágenes. Para ello necesitar bajarte este <a href="http://timthumb.googlecode.com/svn/trunk/timthumb.php">timthumb.php</a>, crear un directorio en tu tema que se llame scripts y copiarlo ahí. Una vez hecho puedes mostrar las imágenes haciendo (en este caso lo redimensionamos a 150&#215;150):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>img src<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;/scripts/timthumb.php?src=/images/nombredelaimagen.jpg&amp;h=150&amp;w=150&amp;zc=1&quot;</span> alt<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;Screenshot&quot;</span> <span style="color: #339933;">/&gt;</span></pre></td></tr></table></div>

<h3>Cambiar de forma automática el tamaño de las imágenes usando funciones internas de Wordpress</h3>
<p>Fuente: <a href="http://www.maverick.it/en/tech/create-thumbnails-using-wordpress-built-in-functions">Create thumbnails using Wordpress built-in functions</a></p>
<p>En wp-includes/media.php hay una serie de funciones que Wordpress usa para manipular ficheros. La que necesitamos es <em>image_resize()</em>:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 *Reducir una imagen a un tamaño concreto y grabar una nueva copia de la imagen.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> image_resize<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$file</span><span style="color: #339933;">,</span> <span style="color: #000088;">$max_w</span><span style="color: #339933;">,</span> <span style="color: #000088;">$max_h</span><span style="color: #339933;">,</span> <span style="color: #000088;">$crop</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$suffix</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$dest_path</span><span style="color: #339933;">=</span><span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #000088;">$jpeg_quality</span><span style="color: #339933;">=</span><span style="color: #cc66cc;">90</span><span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

<p>Puedes usarlo así para crear una nueva imagen de 100×60:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// cambiar el tamaño de la imagen</span>
<span style="color: #000088;">$thumb</span> <span style="color: #339933;">=</span> image_resize<span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">60</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Lo malo es que como Wordpress utiliza esta función en el administrador se necesita algo de código que no está disponible por defecto en los códigos. Esto lo puedes arreglar incluyendo wp-admin/includes/image.php en la prate superior del archivo functions.php de tu tema:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/// admin image API</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>ABSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/wp-admin/includes/image.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<h3 style="color:#F47474; font-style:italic">Relacionados con  Búsquedas</h3>
<h3>Indicar el término incluido en la búsqueda</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;h4&gt;Has buscado &quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_search_query<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;. Aqu&amp;iacute; est&amp;aacute;n los resultados:&lt;/h4&gt;</pre></td></tr></table></div>

<h3>Remarcar el término buscado en los resultados de una búsqueda</h3>
<p>Abre search.php file y sustituye</p>

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

<p>por</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</span> <span style="color: #000088;">$title</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Y justo antes de esa línea recién modificada añade:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #000088;">$title</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: #000088;">$keys</span><span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot; &quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/('</span><span style="color: #339933;">.</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$keys</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span><span style="color: #0000ff;">')/iu'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'&lt;strong class=&quot;search-excerpt&quot;&gt;\0&lt;/strong&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #000088;">$title</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Y en tu hoja de estilos, normalmente style.css, añade:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="css" style="font-family:monospace;">strong<span style="color: #6666ff;">.search-excerpt</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;">yellow</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></td></tr></table></div>

<h3 style="color:#F47474; font-style:italic">Relacionados con Redes Sociales, RSS, Compartir artículos</h3>
<h3>Mostrar un RSS externo</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">include_once</span><span style="color: #009900;">&#40;</span>ABSPATH<span style="color: #339933;">.</span>WPINC<span style="color: #339933;">.</span><span style="color: #0000ff;">'/rss.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
wp_rss<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://wpforums.com/external.php?type=RSS2'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Compartir el artículo por e-mail</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;a href=&quot;mailto:?subject=<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>&amp;amp;body=<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;Send this
article to a friend!&quot;&gt;Email this&lt;/a&gt;</pre></td></tr></table></div>

<h3>Crear un botón para &#8220;Compartir en Facebook&#8221;</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;a href=&quot;http://www.facebook.com/sharer.php?u=<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;t=<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; target=&quot;blank&quot;&gt;Compartir en Facebook&lt;/a&gt;</pre></td></tr></table></div>

<h3>Mostrar enlaces válidos a redes sociales en una tabla</h3>
<p>Requiere añadir los iconos de las redes sociales, que se encuentran facilmente en internet. También requiere el nombre de usuario en Twitter, en vez de la de Alex Denning (de WPShout, autor original del artículo, incluído en Lecturas Recomendadas).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;table border=&quot;0&quot;&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;http://delicious.com/post?url=<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;amp;title=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span>get_the_title<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;Marca este art&amp;iacute;culo en Delicious&quot;&gt;&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/images/delicious.png&quot; alt=&quot;Compartir en Delicious&quot; /&gt;&lt;/a&gt;&lt;/td&gt;
&nbsp;
&lt;td&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;http://digg.com/submit?phase=2&amp;amp;url=<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;Enviar este art&amp;iacute;culo a Digg&quot;&gt;&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/images/digg.png&quot; alt=&quot;Compartir en Digg&quot; /&gt;&lt;/a&gt;&lt;/td&gt;
&nbsp;
&lt;td&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;http://reddit.com/submit?url=<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;amp;title=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span>get_the_title<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;Compartir en Reddit&quot;&gt;&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/images/reddit.png&quot; alt=&quot;Compartir en Reddit&quot; /&gt;&lt;/a&gt;&lt;/td&gt;
&nbsp;
&lt;td&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;http://feeds2.feedburner.com/nombre&quot; title=&quot;Suscribir mediante RSS&quot;&gt;&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/images/rss.png&quot; alt=&quot;Suscribir mediante RSS&quot; /&gt;&lt;/a&gt;&lt;/td&gt;
&nbsp;
&lt;td&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;http://www.stumbleupon.com/submit?url=<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;amp;title=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span>get_the_title<span style="color: #009900;">&#40;</span><span style="color: #000088;">$id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;Compartir en StumbleUpon&quot;&gt;&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/images/stumbleupon.png&quot; alt=&quot;Compartir en StumbleUpon&quot; /&gt;&lt;/a&gt;&lt;/td&gt;
&nbsp;
&lt;td&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;http://twitter.com/home?status=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #990000;">urlencode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;RT @AlexDenning: &quot;</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> 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> --&gt; <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; title=&quot;Compartir con tus seguidores de Twitter&quot;&gt;&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/images/twitter.png&quot; alt=&quot;Compartir en Twitter&quot; /&gt;&lt;/a&gt;&lt;/td&gt;
&nbsp;
&lt;/tr&gt;
&nbsp;
&lt;/table&gt;</pre></td></tr></table></div>

<h3>Mostrar la entrada de Twitter más reciente</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Tu usuario de Twitter.</span>
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;UsuariodeTwitter&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Prefijo - Texto que quieras incluir antes de tus últimos tweets.</span>
<span style="color: #666666; font-style: italic;">// (Puede ser HTML pero asegúrate de poner barras invertidas antes de las comillas, por ejemplo: href=\&quot;link.html\&quot;)</span>
<span style="color: #000088;">$prefix</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Sufijo - texto que quieras mostrar después de tu último tweet. (Mismas reglas que con el prefijo.)</span>
<span style="color: #000088;">$suffix</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$feed</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;http://search.twitter.com/search.atom?q=from:&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$username</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;&amp;rpp=1&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">function</span> parse_feed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000088;">$stepOne</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;content type=<span style="color: #000099; font-weight: bold;">\&quot;</span>html<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$feed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$stepTwo</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&lt;/content&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$stepOne</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tweet</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$stepTwo</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;">$tweet</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span>”<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>”<span style="color: #339933;">,</span> “<span style="color: #339933;">&lt;</span>”<span style="color: #339933;">,</span> <span style="color: #000088;">$tweet</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$tweet</span> <span style="color: #339933;">=</span> <span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span>”<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span>”<span style="color: #339933;">,</span> “<span style="color: #339933;">&gt;</span>”<span style="color: #339933;">,</span> <span style="color: #000088;">$tweet</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">return</span> <span style="color: #000088;">$tweet</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000088;">$twitterFeed</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$feed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$prefix</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> parse_feed<span style="color: #009900;">&#40;</span><span style="color: #000088;">$twitterFeed</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$suffix</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3 style="color:#F47474; font-style:italic">Relacionados con jQuery</h3>
<h3>Incluir jQuery (incluído en la instalación de Wordpress) </h3>
<p>Incluye la propia copia de jQuery incluída en Wordpress. Debe ir antes de wp_head</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_enqueue_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jquery&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Incluir jQuery desde Google (en vez del incluído en Wordpress)</h3>
<p>Se añade este código en functions.php de nuestro tema:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span>is_admin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   wp_deregister_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_register_script<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'jquery'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'1.3.2'</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;">'jquery'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>La última línea logra que no haya hacer nada en el <em>header</em> por lo que con esto bastaría, siempre y cuando en tu tema tengas incluído en la cabecera  <em>wp_head();</em></p>
<h3 style="color:#F47474; font-style:italic">Relacionados con Campos Personalizados</h3>
<h3>Usando campos personalizados (Custom Fields)</h3>
<p><em>Mostrarlos en una lista</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> the_meta<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><em>Utilizar campos personalizados para mostrar imágenes (y cambiarlas su tamaño usando timthumb), con una imagen alternativa si no hubiera imagen</em><br />
Necesitas tener cargado timthumb en tu tema/scripts (ver más arriba cómo usarlo).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$postimageurl</span> <span style="color: #339933;">=</span> get_post_meta<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: #0000ff;">'Image'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</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;">$postimageurl</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span>‘template_url’<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> /scripts/timthumb.php?src=<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_post_meta<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: #0000ff;">&quot;Image&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&amp;h=250&amp;w=250&amp;zc=1&quot; alt=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;img src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'template_url'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/images/noimage.jpg&quot; alt=&quot;No hay imagen disponible&quot; /&gt;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><em>Mostrar el valor de un campo personalizado específico</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_post_meta<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: #0000ff;">'mood'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p><em>Mostrar múltiples valores de un campo personalizado que tiene el mismo ID</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$songs</span> <span style="color: #339933;">=</span> get_post_meta<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: #0000ff;">'songs'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;h3&gt;Art&amp;iacute;culo inspirado por:&lt;/h3&gt;
&lt;ul&gt;
	<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$songs</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$song</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;li&gt;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$song</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
&lt;/ul&gt;</pre></td></tr></table></div>

<p><em>Mostrar un campo personalizado sólo si existe</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
    <span style="color: #000088;">$url</span> <span style="color: #339933;">=</span> get_post_meta<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: #0000ff;">'snippet-reference-URL'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</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;">$url</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;&lt;a href='<span style="color: #006699; font-weight: bold;">$url</span>'&gt;URL de Referenc&amp;iacute;a&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3 style="color:#F47474; font-style:italic">Varios</h3>
<h3>Títulos dinámicos</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?</span>phpif <span style="color: #009900;">&#40;</span>is_home<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: #b1b100;">echo</span> bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>is_404<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: #b1b100;">echo</span> <span style="color: #0000ff;">'404 No Encontrado'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>is_category<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: #b1b100;">echo</span> <span style="color: #0000ff;">'Categor&amp;iacute;a:'</span><span style="color: #339933;">;</span> wp_title<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>is_search<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: #b1b100;">echo</span> <span style="color: #0000ff;">'Resultados de la b&amp;uacute;squeda'</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span> is_day<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_month<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> is_year<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: #b1b100;">echo</span> <span style="color: #0000ff;">'Archivos:'</span><span style="color: #339933;">;</span> wp_title<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
<span style="color: #b1b100;">echo</span> wp_title<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;</pre></td></tr></table></div>

<h3>Incluir una página dentro de otra</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$recent</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;">&quot;page_id=**ID**&quot;</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;">$recent</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;">$recent</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: #000000; font-weight: bold;">?&gt;</span>
       &lt;h3&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;/h3&gt;
       <span style="color: #000000; font-weight: bold;">&lt;?php</span> the_content<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endwhile</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Obtener el ID de la página de jerarquía superior</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #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;">post_parent</span><span style="color: #009900;">&#41;</span>	<span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$ancestors</span><span style="color: #339933;">=</span>get_post_ancestors<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: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$root</span><span style="color: #339933;">=</span><span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ancestors</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$parent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$ancestors</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$root</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000088;">$parent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$post</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ID</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Dar una clase dinámica a <em>body</em> en función del tipo de página, de la categoría, etc..</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;body <span style="color: #000000; font-weight: bold;">&lt;?php</span> body_class<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>&gt;</pre></td></tr></table></div>

<h3>Mostrar una guía (breadcrumbs)  de Inicio/Categoría/Título</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> bloginfo<span style="color: #009900;">&#40;</span>‘home’<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> the_category<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> / <span style="color: #000000; font-weight: bold;">&lt;?php</span> 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></pre></td></tr></table></div>

<h3>Proteger tu e-mail de spam</h3>
<p>Si no tienes más remedio que mostrar tu dirección de e-mail puedes utilizar la función <em>antispambot()</em> que se encuentra en Wordpress:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> antispambot<span style="color: #009900;">&#40;</span>get_the_author_email<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<h3>Uso de la función post_class() para incluir nuestras propias clases</h3>
<p>Permite incluir nuestras propias clases. Su uso sería para añadir la clase <em>estilo</em>, por ejemplo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;div id=&quot;post-<span style="color: #000000; font-weight: bold;">&lt;?php</span> the_ID<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; <span style="color: #000000; font-weight: bold;">&lt;?php</span> post_class<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'estilo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;</pre></td></tr></table></div>

<p>El resultado sería:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>div <span style="color: #000000; font-weight: bold;">class</span><span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post sticky hentry category-icons estilo&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;post-5966&quot;</span><span style="color: #339933;">&gt;</span></pre></td></tr></table></div>

<h3>Lecturas recomendadas y fuentes del artículo</h3>
<p>Wordpress Hacks &#8211; <a href="http://wphacks.com/huge-compilation-of-wordpress-code/">Huge compilation of Wordpress Code</a><br />
WPShout, <a href="http://wpshout.com/10-code-snippets-for-faster-wordpress-coding/">10 Really Useful WordPress Code Snippets</a><br />
Smashing Magazine, <a href="http://www.smashingmagazine.com/2009/06/10/10-useful-wordpress-loop-hacks/">10 Useful WordPress Loop Hacks</a><br />
Smashing Magazine, <a href="http://www.smashingmagazine.com/2009/04/15/10-exceptional-wordpress-hacks/">10 Exceptional WordPress Hacks</a><br />
Vanderlay, <a href="http://vandelaydesign.com/blog/wordpress/hacks-user-interactivity/">9 WordPress Hacks to Encourage User Interactivity</a><br />
Noupe, <a href="http://www.noupe.com/wordpress/mastering-your-wordpress-theme-hacks-and-techniques.html"> Mastering Your WordPress Theme Hacks and Techniques</a></p>
<div id="crp_related"><h3>Artículos relacionados:</h3><ul><li><a href="http://www.emenia.es/internet-explorer-6-y-displayinline/" rel="bookmark" class="crp_title">Internet Explorer 6 y display:inline</a></li><li><a href="http://www.emenia.es/como-separar-los-articulos-por-categorias-en-wordpress/" rel="bookmark" class="crp_title">Cómo separar los artículos por categorías en Wordpress</a></li><li><a href="http://www.emenia.es/funciones-utiles-para-functions-php-en-wordpress/" rel="bookmark" class="crp_title">Funciones útiles para functions.php en Wordpress</a></li><li><a href="http://www.emenia.es/la-funcion-body_class-en-wordpress/" rel="bookmark" class="crp_title">Clases dinámicas en body utilizando la función body_class() de Wordpress</a></li><li><a href="http://www.emenia.es/automatiza-el-ano-del-copyright-en-tu-web/" rel="bookmark" class="crp_title">Automatiza el año del copyright en tu web</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emenia.es/recopilacion-de-45-trucos-para-wordpress/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Barra Lateral diferente para cada página en Wordpress</title>
		<link>http://www.emenia.es/barra-lateral-diferente-para-cada-pagina-en-wordpress/</link>
		<comments>http://www.emenia.es/barra-lateral-diferente-para-cada-pagina-en-wordpress/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 08:16:23 +0000</pubDate>
		<dc:creator>Juan Diaz-Bustamante</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://emenia.es/?p=133</guid>
		<description><![CDATA[En ocasiones necesitamos barras laterales diferentes para distintas páginas de nuestra web en Wordpress. Veremos como hacerlo.]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.emenia.es%2Fbarra-lateral-diferente-para-cada-pagina-en-wordpress%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.emenia.es%2Fbarra-lateral-diferente-para-cada-pagina-en-wordpress%2F&amp;source=JuanDBB_Emenia&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Si tenemos una web creada con Wordpress con contenidos diferentes en páginas distintas, puede que necesitemos <strong>una barra lateral diferente para cada página</strong> de la web. Esto lo podemos conseguir:</p>
<p>a) Con un solo archivo sidebar.php con condicionales que detecten en qué página estamos para aplicar un contenido distinto a cada una.<br />
b) Utilizando barras laterales diferentes repartidas en distintos archivos, uno por cada barra lateral (ejemplo: sidebar-servicios.php, sidebar-productos.php, etc..).<br />
c) En el caso de que utilicemos widgets, veremos cómo usar widgets distintos en cada página.</p>
<h3>Un sólo archivo sidebar.php para todas las barras laterales</h3>
<p>Todo este código (u otro semejante en función de nuestras necesidades) estaría dentro del archivo sidebar.php:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;div id=&quot;sidebar&quot;&gt;
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_home<span style="color: #009900;">&#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;">?&gt;</span> 
  // Código de la barra lateral para la página de Inicio
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>	
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'5'</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;">?&gt;</span> 
  // Código de la barra lateral de la página 5
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>		 
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'4'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'4'</span><span style="color: #009900;">&#41;</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;">?&gt;</span> 
  // Código de la barra lateral para una página de una categoría concreta
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>	
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span>is_search<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;">?&gt;</span> 
  // Código de la barra lateral de la página de búsqueda
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> 
&nbsp;
&lt;/div&gt;</pre></td></tr></table></div>

<p>En este ejemplo concreto estamos diciendo que <strong>si estamos en la página de inicio de la web</strong>, se ejecute un código determinado para la barra lateral, exclusivo para ella. <strong>Si estamos en la página 5 de la web</strong> se ejecutará otro código (para saber el número que corresponde a cada página creada hacemos click en Páginas. Al situar el ratón por encima del nombre de cada página veremos en la barra inferior del navegador el enlace al que va a ir si hacemos click, algo así como <em>/wp-admin/page.php?action=edit&#038;post=15</em>. En este caso el número de la página, su <em>ID</em>, es 15. Cambiaríamos el 5 por un 15) . A continuación indicamos que <strong>si estamos en la categoría 4 o el artículo está dentro de la categoría 4</strong> se ejecute otro código. Y por último, <strong>si estamos en la página de búsqueda</strong> se va a ejecutar otro código diferente. Por supuesto estos condicionales se pueden cambiar en función de nuestras necesidades. Podemos ver más condicionales en <a href="http://codex.wordpress.org/Conditional_Tags" title="Ir a la página de Wordpress">Wordpress.org</a>.</p>
<h3>Un archivo sidebar.php por cada barra lateral</h3>
<p> La manera más sencilla de hacerlo es:<br />
1- Buscar el archivo sidebar.php de tu tema y abrirlo con tu editor.<br />
2- Hacer una copia del mismo grabándola con otro nombre, por ejemplo sidebar-productos.php (recuerda que siempre tiene que mantenerse en el nombre este formato <em>sidebar-NOMBRE.php</em>).<br />
3- En este nuevo archivo introduce todo el código específico de esta nueva barra lateral.<br />
4- Ahora abre la página donde quieres que se muestre esta barra lateral (siguiendo con nuestro ejemplo puede ser una página que se llame productos.php). Normalmente tendrás en esta página una llamada a la barra lateral como esta:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>5- Cambia esta línea por esta otra (en vez de <em>productos</em> puedes poner el nombre que tú le hayas dado al archivo <em>sidebar-NOMBRE.php</em>):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> get_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'productos'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Recordad que entre comillas va el nombre que hemos puesto a nuestra barra lateral. Si es sidebar-NOMBRE.php habría que poner NOMBRE.</p>
<p>Ahora, una vez grabados los cambios, al abrir la página de <em>Productos</em> (o la que hayamos usado para hacer estos cambios) nos saldrá la nueva barra lateral que hemos creado específicamente para esa página.</p>
<h3>Widgets diferentes para páginas diferentes</h3>
<p>Si nuestra barra lateral se crea a base de widgets y queremos que en una página salga un widget y en otra salga otro widget diferente lo primero que tenemos que crear son distintas barras laterales para la página de widgets del administrador. Si en el menú de la izquierda hacemos click en Apariencia y luego en Widgets veremos algo así:</p>
<p><img src="http://emenia.es/wp-content/uploads/2009/10/widgets_1.jpg" alt="widgets_1" title="widgets_1" width="560" height="248" class="aligncenter size-full wp-image-134" /></p>
<p>Para crear más barras laterales tenemos que abrir el archivo functions.php de nuestro tema. Si no existiera habría que crearlo. Normalmente en el archivo functions.php encontramos unas líneas como estas:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
       <span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;li id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;'</span><span style="color: #339933;">,</span>
       <span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">,</span>
       <span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h2 class=&quot;widgettitle&quot;&gt;'</span><span style="color: #339933;">,</span>
       <span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span><span style="color: #339933;">,</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></td></tr></table></div>

<p>Estas líneas crean la barra lateral que vemos en la imagen anterior (el cuadro situado más a la derecha con el nombre <em>Barra Lateral 1</em>) y además dicen qué código HTML incluir antes y después del widget. Los widgets se añaden arrastrando el widget que deseemos al cuadro de la barra lateral (el que se llama en la imagen<em> Barra Lateral 1</em>).</p>
<p>Pero como queremos varias barras laterales diferentes donde arrastrar widgets diferentes cambiaremos el código anterior por uno de este tipo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Barra Lateral Inicio'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'solo_inicio'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;li id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h2 class=&quot;widgettitle&quot;&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#41;</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;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
<span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Barra Lateral Producto'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'solo_producto'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;li id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h2 class=&quot;widgettitle&quot;&gt;'</span><span style="color: #339933;">,</span>
<span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#41;</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;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'register_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	register_sidebar<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Tercera Barra Lateral'</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'tercera_barra'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'before_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;li id=&quot;%1$s&quot; class=&quot;widget %2$s&quot;&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'after_widget'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/li&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'before_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;h2 class=&quot;widgettitle&quot;&gt;'</span><span style="color: #339933;">,</span>
		<span style="color: #0000ff;">'after_title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'&lt;/h2&gt;'</span><span style="color: #339933;">,</span>
	<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Hemos creado tres barras laterales (tres cuadros distintos donde arrastrar widgets). Ahora el lado derecho de la página de Widgets, en el administrador de la web, aparecerá esto:</p>
<p><img src="http://emenia.es/wp-content/uploads/2009/10/widgets.jpg" alt="widgets" title="widgets" width="500" height="390" class="aligncenter size-full wp-image-135" /></p>
<p>Pero vamos a explicar en detalle el código nuevo. Hemos repetido tres veces el código inicial, para crear tres barras laterales. Sólo hemos cambiado para cada una dos cosas: <strong>Su nombre</strong> (el que aparecerá en la cabecera de cada cuadro) que se especifica en <em> &#8216;name&#8217; => &#8216;Tercera Barra Lateral&#8217;</em> y <strong>el ID de cada uno</strong> que se especifica en <em>id&#8217; => &#8216;tercera_barra&#8217;</em>. Un poco más adelante veremos dónde se utiliza este ID único que identifica cada barra lateral con sus widgets propios.</p>
<p><strong>Ahora vamos a situar cada barra lateral dinámica en su página correspondiente</strong>. Antes hemos visto cómo crear distintos archivos sidebar (ejemplos: sidebar-producto.php, sidebar-blog.php, etc&#8230;). Lo más probable es que tengamos unas líneas como estas en el archivo sidebar.php y en cualquiera que hayamos creado a partir de una copia de este:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Este condicional lo que consigue es que si hay widgets se pongan los widgets en la barra lateral, y si no existen se ejecuten las líneas de código que siguen al condicional. Vamos a cambiar este condicional para la página de Producto (siguiendo con el ejemplo anterior) o para la página que deseemos. Para ello en <em>sidebar-producto.php</em> cambiamos ese condicional por:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dynamic_sidebar'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span>dynamic_sidebar<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'solo_producto'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Como vemos hemos añadido el <em>ID</em> de la barra lateral que antes hemos llamado <em>Barra Lateral Producto</em> al añadirla en <em>functions.php</em>.</p>
<p>Ahora en sidebar-producto.php estarán sólo los widgets que hayamos arrastrado a esta barra lateral.</p>
<h3>Otras lecturas recomendadas</h3>
<p>BlogCraving, <a href="http://blogcraving.com/sidebars-pages-wordpress-blog/" title="Ir al artículo">How To: Different Homepage and Single Post Sidebars</a><br />
Wordpress.org, <a href="http://codex.wordpress.org/Customizing_Your_Sidebar" title="Ir al artículo">Customizing Your Sidebar</a><br />
Things by Mike, <a href="http://thingsbymike.com/wordpress-different-sidebar/" title="Ir al artículo">Wordpress – Using a different sidebar for pages and single posts</a>.</p>
<div id="crp_related"><h3>Artículos relacionados:</h3><ul><li><a href="http://www.emenia.es/os-presento-codigoytrucos-com/" rel="bookmark" class="crp_title">Os presento CodigoyTrucos.com</a></li><li><a href="http://www.emenia.es/la-funcion-body_class-en-wordpress/" rel="bookmark" class="crp_title">Clases dinámicas en body utilizando la función body_class() de Wordpress</a></li><li><a href="http://www.emenia.es/primeros-pasos-tras-una-nueva-instalacion-de-wordpress/" rel="bookmark" class="crp_title">Primeros pasos tras una nueva instalación de Wordpress</a></li><li><a href="http://www.emenia.es/como-separar-los-articulos-por-categorias-en-wordpress/" rel="bookmark" class="crp_title">Cómo separar los artículos por categorías en Wordpress</a></li><li><a href="http://www.emenia.es/crea-tu-propia-red-social-con-wordpress-y-buddypress-introduccion/" rel="bookmark" class="crp_title">Crea tu propia red social con Wordpress y BuddyPress &#8211; Introducción</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emenia.es/barra-lateral-diferente-para-cada-pagina-en-wordpress/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Clases dinámicas en body utilizando la función body_class() de Wordpress</title>
		<link>http://www.emenia.es/la-funcion-body_class-en-wordpress/</link>
		<comments>http://www.emenia.es/la-funcion-body_class-en-wordpress/#comments</comments>
		<pubDate>Sun, 27 Sep 2009 15:56:09 +0000</pubDate>
		<dc:creator>Juan Diaz-Bustamante</dc:creator>
				<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://emenia.es/?p=91</guid>
		<description><![CDATA[Introduce clases dinámicas en el elemento body]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.emenia.es%2Fla-funcion-body_class-en-wordpress%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.emenia.es%2Fla-funcion-body_class-en-wordpress%2F&amp;source=JuanDBB_Emenia&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>No hace mucho, y gracias al tema <a href="http://elliotjaystocks.com/starkers/">Starkers</a>, descubrí una nueva función de <a href="http://core.svn.wordpress.org/trunk/wp-includes/post-template.php">wp-includes/post-template.php</a> en Wordpress 2.8, <strong><em>body_class()</em></strong>.</p>
<p>Esta función me ha permitido introducir de manera automática clases en el elemento <strong><em>body</em></strong>, normalmente situado en el archivo header.php de nuestro tema de Wordpress. Estas clases <strong>varían según la página en la que se encuentra el usuario</strong>, y son muy útiles para luego poder aplicar estilos diferentes a cada página.</p>
<p>Se usa así:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;body <span style="color: #000000; font-weight: bold;">&lt;?php</span> body_class<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>&gt;</pre></td></tr></table></div>

<p>Vamos a ver ejemplos de qué genera:</p>
<p><em><strong>Si estamos en la página de inicio y además tenemos el blog en la misma página, la clase que genera es esta:</strong></em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;body class=&quot;home blog&quot;&gt;</pre></td></tr></table></div>

<p>Como vemos genera dos clases separadas que podemos usar en nuestra hoja de estilos.</p>
<p><strong><em>Pero si estamos en la página de inicio y esta es una página estática que no incluye el blog, la clase que generaría podría ser algo como esta:</em></strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;body class=&quot;home page page-id-3 page-template page-template-inicio-php&quot;&gt;</pre></td></tr></table></div>

<p>Como vemos en este caso nos genera diversas clases: una al ser la página de inicio, otra por ser una página, otra que identifica la página y finalmente otra que identifica el template utilizado en la página. Esto nos permite, por ejemplo, aplicar un estilo único a todas las páginas que utilicen un template determinado, o aplicar un diseño individualizado a cada página.</p>
<p>Otro uso perfecto sería para dar estilo a un navegador creado con imágenes, para identificar la página en la que nos encontramos y marcarla como tal.</p>
<p>En el caso de que estemos en un artículo del blog lo que generaría sería algo de este tipo:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;body class=&quot;single postid-71&quot;&gt;</pre></td></tr></table></div>

<p>Lo que nos ayuda a identificar que es un artículo del blog y además lo hace de manera individual, lo que nos permitiría dar un estilo diferente a cada artículo si así lo quisiéramos. </p>
<p><strong>En resumen</strong>, body_class() genera clases CSS dinámicas basadas en el tipo de contenido y en las circunstancias bajo las que estás viendo una página concreta (por ejemplo si estás registrado o no en el caso de solicitarse).</p>
<p>Pero si queremos que además de las clases generadas dinámicamente se añada una clase elegida por nosotros, escribiríamos:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">&lt;body <span style="color: #000000; font-weight: bold;">&lt;?php</span> body_class<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'nombre_clase'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&gt;</pre></td></tr></table></div>

<h3>Más lecturas recomendadas sobre body_class():</h3>
<p><a href="http://www.nathanrice.net/blog/wordpress-2-8-and-the-body_class-function/">Nathan Rice</a> blog.<br />
<a href="http://wpengineer.com/wordpress-28-body_class-automatic_feed_links/">WPEngineer.com</a>, que incluye además una lista completa de las clases que se generan.<br />
<a href="http://xref.yoast.com/trunk/nav.html?wp-includes/post-template.php.source.html#l360">Código</a> de la función get_body_class().<br />
<a href="http://perishablepress.com/press/2009/05/26/dynamic-body-class-id-php-wordpress/">Perisable Press</a> muestra diversas maneras de establecer IDs dinámicos en Wordpress.</p>
<div id="crp_related"><h3>Artículos relacionados:</h3><ul><li><a href="http://www.emenia.es/efecto-de-movimiento-lateral-de-un-elemento-con-hover-en-jquery/" rel="bookmark" class="crp_title">Efecto de movimiento lateral de un enlace con JQuery</a></li><li><a href="http://www.emenia.es/lista-productos-wordpress-3/" rel="bookmark" class="crp_title">Crear una lista de productos con Wordpress 3.0 usando Entradas personalizadas, campos personalizados y taxonomías</a></li><li><a href="http://www.emenia.es/recopilacion-de-45-trucos-para-wordpress/" rel="bookmark" class="crp_title">Recopilación de 45 trucos para Wordpress</a></li><li><a href="http://www.emenia.es/creando-un-menu-vertical-desplegable-con-jquery/" rel="bookmark" class="crp_title">Creando un menú vertical desplegable con jQuery</a></li><li><a href="http://www.emenia.es/como-utilizar-un-fondo-aleatorio-para-nuestra-web/" rel="bookmark" class="crp_title">Como utilizar un fondo aleatorio para nuestra web</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://www.emenia.es/la-funcion-body_class-en-wordpress/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
