Free Checking for Bloggers - Sign up in 5 Minutes! Libre Comprobación de Bloggers - Inscríbase en 5 minutos!
Powered by MaxBlogPress Powered by MaxBlogPress

Wordpress Hack # 1 - query_posts | JTPRATT errores del Blogging
JTPratt errores de los blogs





Home Inicio » Wordpress Hack #1 - query_posts »Wordpress Hack # 1 - query_posts



Wordpress Hack #1 - query_posts Wordpress Hack # 1 - query_posts

1,691 views - 1.691 puntos de vista -

Posted in: Publicado en:

blog-configuración de la categoría de imagenwordpress categoría imagen
1,691 views 1.691 visitas


Please note: This page was originally written in English. Por favor nota: Esta página fue originalmente escrito en Inglés.

The original post can be viewed El post original se puede ver here aquí .

Please note: This page was originally written in English.

The text has been translated using an online service such as Google or Babelfish.

The original post can be viewed here.


This is the very first post in the Este es el primer puesto en la 30 Wordpress Hacks in 30 Days Series 30 Wordpress Hacks en la serie 30 Días !

If you use Wordpress - then this is a series you will want to bookmark right now! Si utiliza Wordpress - entonces esta es una serie que desea favorito ahora! You might even want to subscribe by email at the top of the page. Puede que incluso desea suscribirse por correo electrónico en la parte superior de la página. If you’re like me your sick and tired of googling the crap out of the web trying to find easy ways to hack and customize your Wordpress blog or web site. Si usted es como tu me enfermo y cansado de googling la basura fuera de la web tratando de encontrar formas fáciles de piratear y Wordpress personalizar tu blog o sitio web. I’m going to give you a very useful and easy to perform Wordpress hack every day for a month! Voy a darle una muy útil y fácil de realizar Wordpress hack todos los días durante un mes! I think that it’s easier to do something like this than write a humongous post with more information than you’ll never read or digest in one sitting. Creo que es más fácil hacer algo como esto que humongous escribir un post con más información que usted nunca leer o digerir en una sentada. Instead I’m going to give you one very simple and easy task to do each and every day. En cambio voy a darle una muy simple y fácil tarea de hacer cada uno y todos los días. Depending on your skill level, you may or may not want to take a look at last week’s post Dependiendo de su nivel de destreza, usted puede o no quiere echar un vistazo a la semana pasada después How to Create Your Own Wordpress Theme Cómo crear tu propio tema de Wordpress .

Wordpress Hack #1 - query_posts Wordpress Hack # 1 - query_posts

Today in our very first Wordpress Hack in our 30-day “Hack-a-thon” we’re going to learn about the Wordpress “template tag” query_posts. Hoy, en nuestro primer Hack Wordpress en nuestro 30-día "Hack-a-thon" que vamos a aprender acerca de la Wordpress "plantilla de etiqueta" query_posts. You can Puede read about query_posts in the Wordpress Codex here query_posts leer sobre Wordpress en el Codex aquí . To use any of these examples you must place the PHP code snippet before “the loop”. Para utilizar cualquiera de estos ejemplos usted debe colocar el fragmento de código PHP antes de "el lazo". If you don’t know what “the loop” is, just follow the link in the previous paragraph to create your own wordpress theme for an explanation. Si usted no sabe lo que "el bucle", es decir, sólo tienes que seguir el vínculo que aparece en el párrafo anterior para crear su propio tema para wordpress una explicación. Each and every code snippet can used any any page that uses “the loop”, such as your index.php, category.php, archive.php, tag.php, or search.php. Todos y cada fragmento de código puede utilizarse cualquier página que utilice "el bucle", como su index.php, category.php, archive.php, tag.php, o search.php.

Exclude posts that belong to a category Excluir los puestos que pertenecen a una categoría

Maybe you don’t want posts from a certain category showing up on your index or another archive page. Tal vez usted no quiere que los puestos de una categoría determinada aparecen en su índice u otro archivo de la página. You could even use this to keep certain categories from showing in search results if you needed to. Puede incluso usar esto para mantener determinadas categorías de mostrar en los resultados de búsqueda, si era necesario. You need to know your category “ID” to do this, just retrieve it from your dashboard under “Manage->Categories”, and the “-1″ with your category ID# like this… Lo que necesita saber de su categoría "ID" para ello, sólo recuperar de su escritorio en "Administrar-> Categorías", y el "-1" con su ID # categoría como esta ...

 <?php query_posts('cat=-1'); ?> 

You can exclude multple categories like this… Usted puede excluir multple categorías como este ...

 <?php query_posts("cat=-1,-2,-3"); ?> 

Retrieve a Post or Page Recuperar una entrada o página

To retrieve a particular post you can either call it by ID (listed in your dashboard) or it’s slug like this (use one line of code or the other, not both)… Para recuperar un puesto, usted puede llamar por ID (que aparece en su escritorio) o la babosa como esta (use una línea de código o la otra, no tanto) ...

 <?php query_posts('p=1'); //using post id query_posts('name=first-post'); //using post slug ?> 

You can do the same thing to retrieve pages as well like this… Usted puede hacer lo mismo para recuperar las páginas así como así ...

 <?php query_posts('page_id=7'); //retrieves page 7 only query_posts('pagename=about'); //retrieves the about page only ?> 

When you use those examples it retrieves the entire post. Cuando utilice los ejemplos que recupera todo el correo. When you are notorious for writing extremely long posts (like I am) you may only want to get a partial post with the “read more” link. Cuando son conocidas por escrito extremadamente largas (como yo) puede que sólo desea obtener un puesto de parcial con el enlace "Leer más". This is especialy useful if you’re going ot feature certain posts on your index or other pages. Esto es útil sobre todo si va ot característica de determinados puestos en su índice de páginas o de otro tipo. Here’s the code for that… Aquí está el código para que ...

 <?php query_posts('p=5'); //get post with id of 5 global $more; $more = 0; //gets partial post with read more link ?> 

You know that you can create pages, and you can also create “child pages” like I have on ths site. ¿Sabes que puedes crear páginas, y también puede crear "páginas niño" como yo lo he hecho en mil sitio. I have a parent page called “series”, and then all the individual series index pages are children of that page. Tengo una página principal llamada "serie" y, a continuación, todas las series individuales índice de páginas son los niños de esa página. If you want to get a child page - that’s possible as well, but you can’t call it by id - you have to call it by double-slug as in the example below (parent slug slash child slug). Si desea obtener una página niño - que es posible también, pero no puedes llamarlo por identificación - usted tiene que llamar por doble babosa como en el ejemplo a continuación (los padres del niño barra babosa babosa).

 <?php query_posts('pagename=parent/child'); ?> 

Retrieve Post by Certain Authors Recuperar la posterior por algunos autores

If your blog has multiple authors you can retrive them by name or author id like this… Si su blog tiene varios autores puede retrive por su nombre o ID de autor como este ...

 <?php query_posts('author_name=John'); query_posts('author=3'); ?> 

Retrieve Every Single Post Recuperar todos y cada uno de puesto
Maybe you want to make some kind of an archive page or sitemap. Tal vez usted desea hacer algún tipo de un archivo o página del sitio. Whether or not you create a page with this query of course depends on how many posts you really have, but inserting this code before the loop will list ever post you have all on one page. Ya sea o no de crear una página con esta consulta, por supuesto, depende de cuántos puestos que realmente tienen, pero la inserción de este código antes de que el bucle lista cada vez que se han puesto todos en una sola página. While the code below shows all posts on one page, you can change the “-1″ to just 1 post, or 5, or 10, or however many posts you want to display. Si bien el código de abajo muestra todos los puestos en una sola página, puede cambiar el "-1" a sólo 1, o 5, o 10, o sin embargo muchos puestos que desea visualizar.

 <?php query_posts('posts_per_page=-1'); ?> 

Change the Order or Sequence of Posts Cambiar el orden o secuencia de Correos
By default a Wordpress blog shows you posts in a journal fashion or reverse date order. Por defecto, un blog Wordpress te muestra los puestos en una revista de moda o para invertir la fecha. You could choose to instead sort your posts by author or title like this. Usted puede elegir en lugar de ordenar sus entradas por autor o título como este. You could use either the author or title lines. Puede utilizar cualquiera de los dos el autor o el título líneas.

 <?php query_posts('orderby=author'); query_posts('orderby=title'); ?> 

Using “orderby” there are many different parameters that you can use like these… El uso de "orderby" hay muchos diferentes parámetros que puede utilizar como estos ...

* orderby=author * Orderby = autor
* orderby=date * Orderby = fecha
* orderby=category * Orderby = categoría
* orderby=title * Orderby = título
* orderby=modified * Orderby = modificado
* orderby=menu_order * Orderby = menu_order
* orderby=parent * Orderby = padre
* orderby=ID * Orderby = ID
* orderby=rand * Orderby = rand

Retrieve a Post by Time Period Recuperar la posterior por un período de tiempo

There are many different ways to consruct a query to retrieve certain posts based by date only. Hay muchas maneras diferentes de consruct una consulta para recuperar algunos puestos sólo por fecha. Here’sa way to get them for a day of the month… Aquí hay una manera de obtener para ellos un día del mes ...

 <?php query_posts('day=15'); //all posts on the 15th ?> 

You could also get them for the current month and year with a query like this… También puede obtener para el actual mes y año, con una consulta como esta ...

 <?php $current_month = date('m'); ?> <?php $current_year = date('Y'); ?> <?php query_posts("cat=22&year=$current_year&monthnum=$current_month&order=ASC"); ?> 

Retrieve Posts based on Tags Recuperar puestos sobre la base de Tags
You can retrieve posts for a specific tag or tags like this (use one line of code at a time only). Puede recuperar los puestos para un determinado etiqueta o etiquetas de este tipo (usar una línea de código en un momento solamente). The first line retrieves posts with a particular tag, the second line is the format for getting posts for multiple tags, but the third line is for getting posts that were tagged in multiple categories. La primera línea indica los puestos con una etiqueta particular, la segunda línea es el formato para obtener puestos de múltiples etiquetas, pero la tercera línea es para conseguir puestos que estaban etiquetados en múltiples categorías. In other words the second line will retrieve all posts tagged as bread all posts tagged as baking. En otras palabras, la segunda línea de recuperar todos los puestos etiquetados como pan de todos los puestos etiquetados como hornear. But the third line will get only posts tagged in bread and baking and recipe. Sin embargo, la tercera línea de obtener sólo los puestos marcados en el pan y hornear, y la receta.

 <?php query_posts('tag=cooking'); query_posts('tag=bread,baking'); query_posts('tag=bread+baking+recipe'); ?> 

I hope this helps you do a little Wordpress “theme hacking” and customize your blog. Espero que esto le ayuda a hacer un poco de Wordpress "tema de la piratería" y personalizar tu blog. If you have any questions about query_posts please comment now, and we’ll see your tomorrow for the next hack! Si usted tiene alguna pregunta acerca de query_posts comentario por favor ahora, y vamos a ver su mañana para el próximo truco!


Tags: , ,

5 Responses to “Wordpress Hack #1 - query_posts” 5 Responses to "Wordpress Hack # 1 - query_posts"

  1. Mark Wilson Marca Wilson Has the following to say... Tiene las siguientes decir ...

    I had actually been looking for the one about authors. Yo había estado buscando el uno acerca de los autores.
    thanks a lot, it been a big help. Muchas gracias, es una gran ayuda.

    Mark Wilson’s last blog post.. Wilson marca la última entrada en el blog .. I hate the word “niche†Odio la palabra à ¢ â, ¬ Å "nicheà ¢ â, ¬ Â

  2. Make Money Blogging Gana dinero de blogs Has the following to say... Tiene las siguientes decir ...

    Loving the idea even though this one is sort of irrelevant for me, cannot wait for the rest. Amante de la idea, aunque esta es una especie de irrelevante para mí, no puede esperar para el resto.

  3. Erika Erika Has the following to say... Tiene las siguientes decir ...

    Okay… as a wordpress newbie (but someone who chose to dive head-first into WP development… silly me) I can’t tell you how much I value this series that you’re doin! Bueno ... como un novato wordpress (pero alguien que optó por la cabeza de buceo en primer WP desarrollo tonto me ...) No puedo decirle lo mucho que el valor de esta serie que estás haciendo! Once I finally get my blog up and running, I’m going to have to toss out a thank-you for helping me so much! Una vez que finalmente llegan a mi blog en marcha y funcionando, voy a tener que echar un gracias por ayudarme tanto!

  4. admin admin Has the following to say... Tiene las siguientes decir ...

    @Erika - glad to help! @ Erika - encantados de ayudarle! I love comments like this, because it means I made the right decision in starting this series… Me encantan los comentarios como este, porque significa que hice la decisión correcta en el inicio de esta serie ... =

  5. The Genesis: Welcome to Internet Espionage, Awesome WP Links, and More | Internet Espionage El Génesis: Recepción Espionaje a Internet, Genial WP Links, y Más | Espionaje Internet Has the following to say... Tiene las siguientes decir ...

    [...] — Hacking query_posts in WordPress — In his attempt to present readers with 30 wordpress hacks in 30 days, the first in his [...] [...] - Hacking query_posts en WordPress - En su intento de presentar los lectores con 30 wordpress hacks en 30 días, la primera en su [...]

Question or Comment?? Pregunta o comentario? Spill it Now... Derrame Ahora ...

Saltos de alegría en los comentarios!

We Reward Comments! Nos recompensa comentarios!


We dofollow links, and get your latest blog post as a byline under every new comment from the "CommentLuv" plugin! Estamos dofollow enlaces, y obtener su última entrada en el blog como un byline el marco de cada nuevo comentario de la "CommentLuv" plugin! Top commenters for every month are listed on every page of this site in a sidebar widget linked back to your URL! Comienzo de la página comentaristas para cada mes se muestran en cada página de este sitio web en un widget lateral vinculado de nuevo a su URL! We would like to reward you for becoming part of our community! Nos gustaría recompensar a usted para ser parte de nuestra comunidad! Your comment is valuable not only to us, but also all the other readers of this blog! Su comentario es valioso no sólo para nosotros, sino también todos los demás lectores de este blog!


Click to add smilies to your post! Haz clic para añadir emoticones a su puesto! == []^ = (= ((= (|=) r= | 8= 0=) ~= 00= (=;;=)]=;;;