Posted in: Publicado em:
1,453 views 1453 visualizações
Please note: This page was originally written in English. Atenção: Esta página foi originalmente escrito em Inglês.
The original post can be viewed O post original pode ser visualizada here aqui .
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 Esta é a primeira postagem na 30 Wordpress Hacks in 30 Days Series 30 Wordpress Hacks Series em 30 Dias !
If you use Wordpress - then this is a series you will want to bookmark right now! Se você usar Wordpress - então esta é uma série que você vai querer favorito agora mesmo! You might even want to subscribe by email at the top of the page. Você pode até querer inscrever por e-mail na parte superior da 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. Se você gosta de mim o seu farto de googling o crap fora da web tentando encontrar maneiras fáceis de Wordpress hack e personalize o seu blog ou site. I’m going to give you a very useful and easy to perform Wordpress hack every day for a month! Eu vou te dar um muito útil e de fácil execução Wordpress hack todos os dias durante um mês! 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. Acho que é mais fácil fazer algo parecido com isso do que escrever um enorme post com mais informações do que você nunca leu ou digerir em uma sessão. Instead I’m going to give you one very simple and easy task to do each and every day. Em vez disso, vou dar-te uma tarefa muito simples e fácil de fazer todo dia. Depending on your skill level, you may or may not want to take a look at last week’s post Dependendo do seu nível de qualificação que podem ou não querem dar uma olhada na semana passada no pós How to Create Your Own Wordpress Theme Como criar seu próprio tema 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. Hoje, em nosso primeiro Wordpress Hack no nosso 30-dia "Hack-a-thon" nós estamos indo para aprender sobre o Wordpress "tag de modelo" query_posts. You can Você pode read about query_posts in the Wordpress Codex here query_posts em ler sobre o Wordpress Codex aqui . To use any of these examples you must place the PHP code snippet before “the loop”. Para utilizar qualquer um destes exemplos que você deve colocar o código PHP trecho antes de "loop". 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. Se você não sabe o que "o ciclo" está, basta seguir o link no parágrafo anterior para criar seu próprio wordpress tema para uma explicação. 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. Todo e qualquer código pode utilizar qualquer trecho qualquer página que usa o "loop", tais como o seu index.php, category.php, archive.php, tag.php, ou search.php.
Exclude posts that belong to a category Excluir postagens que pertencem a uma categoria
Maybe you don’t want posts from a certain category showing up on your index or another archive page. Talvez você não queira postagens de uma determinada categoria aparecendo no seu índice ou outro arquivo página. You could even use this to keep certain categories from showing in search results if you needed to. Você poderia até usar isso para manter a certas categorias sejam exibidos nos resultados da pesquisa se você necessários. 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… Você precisa conhecer a sua categoria "ID" para fazer isso, basta recuperá-lo do seu painel, em "Gerenciar-> Categorias", eo "-1", com a sua categoria ID # como este ...
<?php query_posts('cat=-1'); ?> You can exclude multple categories like this… Você pode excluir multple categorias como este ...
<?php query_posts("cat=-1,-2,-3"); ?> Retrieve a Post or Page Recuperar uma Página ou Correios
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 um determinado posto você pode chamá-la pelo ID (listados em seu painel) ou é lesma como este (use uma linha de código ou de outra, nem 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… Você pode fazer a mesma coisa para recuperar páginas tão bem como esta ...
<?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. Quando você usar esses exemplos ele recupera a totalidade do post. 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. Quando são notórias para escrever posts extremamente longos (como eu sou) você só pode desejar para obter um posto parcial com o link "Leia mais". This is especialy useful if you’re going ot feature certain posts on your index or other pages. Isto é especialmente útil se você vai ot característica de determinados postos em seu índice ou outras páginas. Here’s the code for that… Veja abaixo o 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. Você sabe que você pode criar páginas, e você também pode criar "páginas criança" como eu tenho sobre THS site. I have a parent page called “series”, and then all the individual series index pages are children of that page. Eu tenho uma página pai chamada "série" e, em seguida, todas as séries individuais páginas índice são filhos dessa 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). Se você deseja obter uma criança página - isso é possível, pois bem, mas você não pode chamá-lo pelo id - você tem que chamá-la pelo dobro-bala, como no exemplo abaixo (pai lesma lesma slash criança).
<?php query_posts('pagename=parent/child'); ?> Retrieve Post by Certain Authors Recuperar post por certos autores
If your blog has multiple authors you can retrive them by name or author id like this… Se o seu blog possui vários autores, pode recuperar-los pelo nome do autor ou id como este ...
<?php query_posts('author_name=John'); query_posts('author=3'); ?> Retrieve Every Single Post Obter cada único post
Maybe you want to make some kind of an archive page or sitemap. Talvez você queira fazer algum tipo de página ou um arquivo sitemap. 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. Mesmo que você não crie uma página com essa pesquisa do curso depende de quantos lugares você realmente tem, mas inserir esse código antes do loop irá apresentar uma lista que tenha alguma vez posto em toda uma 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. Embora o código abaixo mostra todas as postagens de uma página, você pode mudar a "-1" para apenas 1 post, ou 5, ou 10, ou no entanto muitos lugares que você quer exibir.
<?php query_posts('posts_per_page=-1'); ?> Change the Order or Sequence of Posts Alterar a Ordem dos Correios ou Sequence
By default a Wordpress blog shows you posts in a journal fashion or reverse date order. Por defeito um blog mostra postos Wordpress em um jornal ou de moda data ordem inversa. You could choose to instead sort your posts by author or title like this. Você poderá escolher em vez de classificar os postos por autor ou título como esse. You could use either the author or title lines. Você poderá usar tanto o autor ou título linhas.
<?php query_posts('orderby=author'); query_posts('orderby=title'); ?> Using “orderby” there are many different parameters that you can use like these… Usando "orderby" existem muitos parâmetros diferentes que você pode usar como estes ...
* orderby=author * = Orderby autor
* orderby=date * = Orderby data
* orderby=category * = Orderby categoria
* orderby=title * Orderby title =
* orderby=modified * = Orderby modificados
* orderby=menu_order * = Orderby menu_order
* orderby=parent * = Orderby mãe
* orderby=ID * Orderby ID =
* orderby=rand * Orderby = rand
Retrieve a Post by Time Period Post por uma Recupere Tempo Período
There are many different ways to consruct a query to retrieve certain posts based by date only. Existem muitas maneiras diferentes de consruct uma consulta para recuperar alguns lugares até basear somente data. Here’sa way to get them for a day of the month… Aqui o caminho para obtê-los por um dia do mês ...
<?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… Você também pode obtê-los para o corrente mês e ano, com uma pergunta 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 Obter Posts baseados em Tags
You can retrieve posts for a specific tag or tags like this (use one line of code at a time only). Você pode recuperar lugares específicos para uma etiqueta ou etiquetas como esta (use uma linha de código em uma só vez). 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. A primeira linha recupera lugares com uma etiqueta especial, a segunda linha é o formato para vários lugares para se colocar tags, mas a terceira linha é para ficar postagens que foram marcados em várias categorias. In other words the second line will retrieve all posts tagged as bread all posts tagged as baking. Em outras palavras, a segunda linha irá recuperar todos os lugares marcados como pão todos os lugares marcados como fermento. But the third line will get only posts tagged in bread and baking and recipe. Mas a terceira linha vai ficar apenas em lugares marcados e assando pão e receita.
<?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 isso ajude você fizer um pouco Wordpress "tema hacking" e personalizar seu blog. If you have any questions about query_posts please comment now, and we’ll see your tomorrow for the next hack! Se você tiver alguma dúvida sobre a query_posts queira comentar agora, e vamos ver seu prostituir-se amanhã para a próxima!
Tags: blog-help blog-ajuda , tutorial , wordpress-hacks



























April 15th, 2008 at 12:08 am 15 de abril, 2008 em 12:08 am
I had actually been looking for the one about authors. Eu tinha sido realmente à procura de um sobre o autor.
thanks a lot, it been a big help. agradecimentos muito, ela foi uma grande ajuda.
Mark Wilson’s last blog post.. Mark Wilson's última postagem no blog .. I hate the word “niche†Eu odeio a palavra â € œnicheâ €
April 15th, 2008 at 9:04 am 15 de abril, 2008 em 9:04 am
Loving the idea even though this one is sort of irrelevant for me, cannot wait for the rest. A ideia amorável, embora esta seja uma espécie de irrelevante para mim, não pode esperar para o resto.
April 28th, 2008 at 10:41 pm 28 de abril, 2008 em 10:41 pm
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! Ok ... como um newbie wordpress (mas alguém que escolheu a mergulhar em primeiro cabeça-WP-me tonto desenvolvimento ...) Não posso te dizer o quanto gosto valor desta série que você está fazendo! 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! Depois que finalmente eu recebo meu blog instalado e funcionando, eu vou ter que atirar para fora um agradecer-lhe por me ajudar tanto!
April 29th, 2008 at 7:59 am 29 de abril, 2008 em 7:59 am
@Erika - glad to help! @ Erika - feliz em ajudar! I love comments like this, because it means I made the right decision in starting this series… Adoro comentários como este, porque significa que fiz a decisão certa no início desta série ...
August 20th, 2008 at 6:20 pm 20 de agosto, 2008 em 6:20 pm
[...] — Hacking query_posts in WordPress — In his attempt to present readers with 30 wordpress hacks in 30 days, the first in his [...] [...] - Hackers query_posts em WordPress - Em sua tentativa de apresentar leitores com 30 wordpress hacks em 30 dias, o primeiro em sua [...]