Posted in: 張貼在:
629 views 629的意見
Please note: This page was originally written in English.請注意:此頁中,原本以英文書寫。
The original post can be viewed原來的文章可以看 here這裡 . 。
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這是很後的第一次,在 30 Wordpress Hacks in 30 Days Series 30日在WordPress駭客在30天內的一系列 ! !
If you use Wordpress - then this is a series you will want to bookmark right now!如果您使用的WordPress -然後,這是一個系列,你將要加入書籤的權利! You might even want to subscribe by email at the top of the page.你甚至可能想訂閱通過電子郵件在網頁上方。 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.如果您一樣,讓我看看你的病假和厭倦了在Google上搜尋該crap出來的Web試圖尋找簡便的方法來入侵並自訂您的WordPress博客或網站。 I’m going to give you a very useful and easy to perform Wordpress hack every day for a month!我要去給你一個非常有用的和容易執行的WordPress哈克每天為一個月! 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.我認為這更容易做一些事情一樣,這比寫一humongous後提供更多資料,比你將永遠不會閱讀或消化在一會議。 Instead I’m going to give you one very simple and easy task to do each and every day.不是我要去給你一個非常簡單和輕鬆的工作做的每一天。 Depending on your skill level, you may or may not want to take a look at last week’s post根據您的技能水平,你可能會或不會要考慮一下在上週的後 How to Create Your Own Wordpress Theme 如何創建您自己的WordPress主題 . 。
Wordpress Hack #1 - query_posts在WordPress哈克# 1 -q uery_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.今天在我們非常第一的WordPress哈克在我們30天的“哈克一來到Thon : ”我們正在以了解有關的WordPress “模板標記” query_posts 。 You can您可以 read about query_posts in the Wordpress Codex here閱讀有關query_posts ,在食品法典委員會在這裡的WordPress . 。 To use any of these examples you must place the PHP code snippet before “the loop”.使用任何這些例子,你必須把PHP代碼片段之前的“循環” 。 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.如果您不知道什麼是“循環”是,只需按照以下的聯繫,在過去的段要創建您自己的WordPress的主題為一解釋。 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.每一個代碼段可以使用任何的任何網頁,使用“河套” ,如在您的index.php , category.php , archive.php , tag.php ,或search.php 。
Exclude posts that belong to a category 排除職位,屬於一類
Maybe you don’t want posts from a certain category showing up on your index or another archive page.也許你不想員額從某一類出現在您的指數或其他存檔頁。 You could even use this to keep certain categories from showing in search results if you needed to.你甚至可以用它來保持某些類別顯示在搜索結果中如果你需要。 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…您需要知道您的類別“身份證” ,若要這麼做,只要找回它從您的儀表板下的“管理” ->類別“ ,以及” - 1“與您的類別I D#喜歡這個…
<?php query_posts('cat=-1'); ?> < ? PHP的query_posts ( '貓=- 1 ' ) ; ? > You can exclude multple categories like this…您可以排除multple類別喜歡這個…
<?php query_posts("cat=-1,-2,-3"); ?> < ? PHP的query_posts ( “貓=- 1 , -2 , -3 ” ) ; ? > Retrieve a Post or Page 取出一個職位或網頁
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)…中取出一個特定職位,您可以調用它的編號(列在您的儀表板) ,或者它的塞一樣,這(使用一代碼行或其他,而不能兩者都) … …
<?php query_posts('p=1'); //using post id query_posts('name=first-post'); //using post slug ?> < ? PHP的query_posts ( ' P值1 ' ) ; / /使用郵政編號query_posts ( '名稱=第一員額' ) ; / /使用後塞? > You can do the same thing to retrieve pages as well like this…你可以做同樣的事情檢索的頁面,以及像這樣…
<?php query_posts('page_id=7'); //retrieves page 7 only query_posts('pagename=about'); //retrieves the about page only ?> < ? PHP的query_posts ( ' page_id = 7 ' ) ; / /檢索第7頁,只有query_posts ( '頁=約' ) ; / /檢索頁,只有約? > When you use those examples it retrieves the entire 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.當您是惡名昭彰的寫作極長的職位(如我) ,您可能只想得到了部分郵政與“閱讀更多內容”鏈接。 This is especialy useful if you’re going ot feature certain posts on your index or other pages.這是especialy有用如果您前往酒店功能,某些職位對您的指數或其他的頁面。 Here’s the code for that…這裡的代碼為…
<?php query_posts('p=5'); //get post with id of 5 global $more; $more = 0; //gets partial post with read more link ?> < ? PHP的query_posts ( ' P值5 ' ) ; / /獲取職位的ID全球5元以上;元,更= 0 ; / /取得部分郵政與閱讀更多鏈接? > You know that you can create pages, and you can also create “child pages” like I have on ths site.您知道您可以創建的頁面,您也可以建立“兒童的頁面”就像我曾在ths網站。 I have a parent page called “series”, and then all the individual series index pages are children of that page.我有一個父頁面的所謂“系列” ,然後所有個別的一系列指數的頁面是兒童該網頁。 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).如果您想要得到的兒童網頁-這就是盡可能好,但您無法通話,它的編號-你必須調用它的雙塞作為在下面的例子中(母公司塞斜線兒童塞) 。
<?php query_posts('pagename=parent/child'); ?> < ? PHP的query_posts ( '頁=父母/子女' ) ; ? > Retrieve Post by Certain Authors 檢索後由某些作者
If your blog has multiple authors you can retrive them by name or author id like this…如果您的博客有多個作者,您可以retrive他們的姓名,名稱或作者的ID喜歡這個…
<?php query_posts('author_name=John'); query_posts('author=3'); ?> < ? PHP的query_posts ( ' author_name =約翰' ) ; query_posts ( '作者= 3 ' ) ; ? > Retrieve Every Single Post 擷取每一個單一的工作地點
Maybe you want to make some kind of an archive page or 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.不論您是否建立一個網頁與此查詢,當然,取決於有多少職位,你真的,但插入此代碼前環路將列出以往任何時候都後,你都在同一頁上。 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.而下面的代碼顯示所有的職位在同一頁上,您可以更改“ -1 ”只是1個員額,或五,或10 ,或職位,但許多你想要顯示的。
<?php query_posts('posts_per_page=-1'); ?> < ? PHP的query_posts ( ' posts_per_page =- 1 ' ) ; ? > Change the Order or Sequence of Posts 變更順序或序列的職位
By default a Wordpress blog shows you posts in a journal fashion or reverse date order.默認情況下,一WordPress所博客顯示您的職位,在時尚雜誌或反向日期秩序。 You could choose to instead sort your posts by author or title like this.您可以選擇而不是排序您的職位,按作者或書名喜歡這個。 You could use either the author or title lines.您可以使用,無論是作者或標題行。
<?php query_posts('orderby=author'); query_posts('orderby=title'); ?> < ? PHP的query_posts ( '的OrderBy =作者' ) ; query_posts ( '的OrderBy =標題' ) ; ? > Using “orderby” there are many different parameters that you can use like these…使用“的OrderBy ”有很多不同的參數,您可以使用像這些…
* orderby=author * =作者的OrderBy
* orderby=date *日期的OrderBy =
* orderby=category *類的OrderBy =
* orderby=title *標題的OrderBy =
* orderby=modified *修飾的OrderBy =
* orderby=menu_order *的OrderBy = menu_order
* orderby=parent *家長的OrderBy =
* orderby=ID *編號的OrderBy =
* orderby=rand *蘭德公司的OrderBy =
Retrieve a Post by Time Period 取出一個郵政所的時間
There are many different ways to consruct a query to retrieve certain posts based by date only.有許多不同的方式,以consruct查詢檢索某些職位為基礎的日期而已。 Here’sa way to get them for a day of the month…這裡的方式,讓他們為一個月的第一天起…
<?php query_posts('day=15'); //all posts on the 15th ?> < ? PHP的query_posts ( '天= 15 ' ) ; / /所有職位於15日? > You could also get them for the current month and year with a query like this…您也可以讓他們為當前的年份和月份與查詢,這樣的…
<?php $current_month = date('m'); ?> <?php $current_year = date('Y'); ?> <?php query_posts("cat=22&year=$current_year&monthnum=$current_month&order=ASC"); ?> < ? PHP的美元current_month =日期( '米' ) ; ? > < ? PHP的美元current_year =日期(以 Y ' ) ; ? > < ? PHP的query_posts ( “貓= 22 &年= $ current_year & monthnum = $ current_month與秩序的ASC = ” ) ; ? > Retrieve Posts based on Tags 檢索職位的基礎上標籤
You can retrieve posts for a specific tag or tags like this (use one line of code at a time only).您可以檢索職位,為某一特定標記或標記一樣,這(使用一個代碼行,在一個時間只) 。 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.第一線的職位檢索與特定的標記,第二行是格式獲得職位為多個標籤,但第三行是為獲得職位,分別標記在多個類別。 In other words the second line will retrieve all posts tagged as bread all posts tagged as baking.在其他的話,第二行會擷取所有職位標記作為麵包的所有帖子標記作為烘焙。 But the third line will get only posts tagged in bread and baking and recipe.但三線,將只能得到職位的標記在麵包及烘烤和食譜。
<?php query_posts('tag=cooking'); query_posts('tag=bread,baking'); query_posts('tag=bread+baking+recipe'); ?> < ? PHP的query_posts ( '標記=烹飪' ) ; query_posts ( '標記=麵包,烘焙' ) ; query_posts ( '標記= +麵包烘焙食譜+ ' ) ; ? > I hope this helps you do a little Wordpress “theme hacking” and customize your blog.我希望這將幫助您做一些在WordPress “主題黑客” ,並自訂您的博客。 If you have any questions about query_posts please comment now, and we’ll see your tomorrow for the next hack!如果您有任何疑問,請評論query_posts現在,我們將看到您的明天,為下一步入侵!
Tags:標籤: blog-help博客幫助 , , tutorial補習 , , wordpress-hacks在WordPress -駭客






















April 15th, 2008 at 12:08 am 2008年4月15日在上午12時08分
I had actually been looking for the one about authors.我其實一直在尋找一個約作者。
thanks a lot, it been a big help.感謝了很多,它的一大幫助。
Mark Wilson’s last blog post.. 馬克威爾遜的最後的博客帖子.. I hate the word “niche†我恨這個詞â € € œnicheâ
April 15th, 2008 at 9:04 am 2008年4月15日在上午09時04分
Loving the idea even though this one is sort of irrelevant for me, cannot wait for the rest.愛的想法,即使這是一類無關,我不能等待,其餘的。
April 28th, 2008 at 10:41 pm 2008年4月28日在下午10時41分
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!好…作為一個在WordPress新手(但有人誰選擇潛水元首首次到可濕性粉劑發展…愚蠢的我)我不能告訴你我是多麼的價值,這一連串您doin ! 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!有一次我終於得到我的博客和運行,我會要折騰了一個感謝您幫助我這麼多!
April 29th, 2008 at 7:59 am 2008年4月29日在上午07時59分
@Erika - glad to help! @埃里卡-高興的幫助! I love comments like this, because it means I made the right decision in starting this series…我愛的評論一樣,這一點,因為這意味著我作出了正確的決定,開始這一系列…