檢索并且得到WordPress崗位ID在圈之外當PHP可變物
在WordPress,每個崗位有獨特的船錨標識符以數字崗位ID.的形式 當在圈裡面, WordPress處理并且顯示在當前時期將顯示的每一個崗位并且根據時怎樣格式化他們他們在圈標記之內配比指定了標準,模板標記the_ID可以用於容易地顯示崗位的ID在崗位裡面。 二者擇一地,在the_content過濾器裡面,宣稱$id全球性并且使用$id檢索崗位ID.
the_ID模板標記可以用於以下格式:
<?php the_ID (); ?>
在圈之外或在崗位的上下文外面,例如在步行者倒栽跳水和甚而側杆區域在WordPress的blog模板, the_ID ()不可能使用作為作用。 反而, $post->ID將用於退回崗位ID (句法可能也使用在崗位的圈裡面通過宣稱$post如全球性)。 $post是舉行關於在頁顯示的崗位的各種各樣的信息的一個全球性對象。 如此$post->ID將退回崗位的崗位ID。 $post使用在作用的它, $post裡面必須被宣稱作為一個全局變量。 例如:
//運作在圈裡面
作用function_name () {
全球性$post;
$thePostID = $post->ID;
}
或:
//在唯一崗位運作在圈外面
作用function_name () {
全球性$wp_query;
$thePostID = $wp_query->post->ID;
}
$post->ID可以叫太直接地在圈外面在一塊唯一崗位模板,例如 <?php回聲$post->ID ?> 將打印顯示崗位的ID數字。
在多個崗位觀看頁例如索引頁或檔案頁,檢索得到新是可能的或最早期的崗位所有崗位ID在頁顯示了通過使用命令由條目命令崗位不遲於日期,然後設置紀錄數限制1。
例如和有各種各樣的方式使用詢問:
//Get最新的崗位ID數字
$post->ID命令由post_date ASC極限1
//Get最早的崗位ID數字
$post->ID命令由post_date DESC極限1
重要: 這是現狀提供,不用保單的機器翻譯的頁。 計算機翻譯也許是難瞭解。 參見 原始的英國文章 每當可能。
分享并且貢獻或者得到技術支持并且幫助在 我的數字式生活論壇.
相關文章
- Paginating or Split WordPress Post or Page with NextPage in WordPress Not Working
- Disable and Turn Off Post Revisions Tracking in WordPress 2.6 or Above
- How to Change the Frequency or Interval WordPress Auto Saves An Editing Post or Page
- WordPress MySQL SQL Query Error in WPDB Class
- Adding Extra More Fields to WordPress Write/Edit Post/Page Right Column
- Disable Auto Go To (Jump) To Read More Tag
- How To Store Every Post Revisions on Each Auto-Save in WordPress with Limit on Versions Count
- 3 Column Relaxation WordPress Theme comments-paged.php for Paged-Comments WordPress Plugin
- How to Delete Existing WordPress Post Revisions Stored/Saved
- Integrate WordPress including Comments with bbPress Forum using bbSync

































December 1st, 2006 06:06
This is really good thing to know… I think i’ll try to use this with my blog and limited php knowledge.
May 3rd, 2007 05:10
Just what I was looking for, thanks!
May 16th, 2007 14:15
Found this through Google. Thanks! You should also enter this into the official WP documentation wiki: http://codex.wordpress.org/Main_Page
June 28th, 2007 11:55
Great info. Needed this a few days ago. Will update my code with this direct approach. Thanks.
September 21st, 2007 07:51
Thanks, using ‘global $id;’ in a filter for my plugin got me the post id I needed.
October 6th, 2007 00:09
comment_fashion
October 10th, 2007 21:05
[...] 使用post ID变量可以做到。$post->ID可以返回文章的唯一编号。 [...]
April 18th, 2008 18:11
Thanks! That’s just what i am looking for. I want to get post id on the wordpress index (root) page.
May 6th, 2008 20:02
Thanks for this. You cant believe how long it took me to search for this simple answer! I dont know why you cant find it on wordpress.
June 16th, 2008 03:27
Hi,
thanks for these informations.
I tried to configure something without any luck and hope you can help me.
I’m using wordpress as a blog and do have a few pictures in every blog.
Now I want to implement a feature like shadowbox to popup the images. To do this automatically, I put a rel=”shadowbox[imageset]” in the anchors of the images.
What do I have to do to put the post-title or ID instead of imageset.
Is something like this possible?
June 16th, 2008 03:27
Forgot Notification of followups. Thanks.
June 17th, 2008 14:02
Thank you. It works like a charm!
June 18th, 2008 09:34
Thanks for this - this did absolutely what I needed to do.